예제 #1
0
        /// <summary>
        /// Disposes of the trace listener.
        /// </summary>
        /// <param name="disposing">A value indicating whether to dispose managed and unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_lockStream != null && _lockStream.AcquireLock())
                {
                    try
                    {
                        _writer.Close();
                    }
                    finally
                    {
                        _lockStream.ReleaseLock();
                    }

                    _lockStream.Close();
                }

                _writer = null;
                _lockHandler = null;
                _lockStream = null;
            }

            base.Dispose(disposing);
        }
예제 #2
0
        /// <summary>
        /// Open the file.
        /// </summary>
        protected void OpenFile()
        {
            if (_filePath != null)
            {
                try
                {
                    EnsureFileDirectory();

                    _lockHandler = CreateLockHandler();
                    _lockHandler.OpenFile(_filePath, AppendToFile, Encoding);
                    _lockStream = new FileLockStream(_lockHandler);
                }
                catch (Exception ex)
                {
                    Fail(ex.Message, ex.ToString());
                    if (Debugger.IsAttached)
                    {
                        throw;
                    }
                }

                if (AcquireLock())
                {
                    try
                    {
                        _writer = new StreamWriter(_lockStream, Encoding);
                    }
                    finally
                    {
                        ReleaseLock();
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Close the file.
        /// </summary>
        protected void CloseFile()
        {
            if (_filePath != null)
            {
                if (AcquireLock())
                {
                    try
                    {
                        _writer.Close();
                    }
                    finally
                    {
                        ReleaseLock();
                    }
                }

                _writer = null;
                _lockHandler = null;
                _lockStream = null;
            }
        }