/// <summary> /// Activate the options that were previously set with calls to properties. /// </summary> virtual public void ActivateOptions() { // Close the current asynchronous processing. Close(); // Check the asynchronous layout. if (Layout == null) { throw new LogException(Resources.Strings.AsyncLayoutIsNull); } // Check the asynchronous strategy. if (Strategy == null) { throw new LogException(Resources.Strings.AsyncStrategyIsNull); } // Check the asynchronous target appender. if (Appender == null) { throw new LogException(Resources.Strings.AsyncAppenderIsNull); } _asyncLayout = Layout; _asyncStrategy = Strategy; _asyncAppender = Appender; // Start new asynchronous processing. _asyncStrategy.HandleItem += loggingMessage => Appender.DoAppend(loggingMessage); _asyncStrategy.HandleOverflow += bufferLimit => ErrorHandler.Error(string.Format(Resources.Strings.AsyncQueueOverflow, bufferLimit)); _asyncStrategy.StartProcessing(); // Append header. if (!string.IsNullOrEmpty(_asyncLayout.Header)) { _asyncStrategy.AddItem(_asyncLayout.Header + Environment.NewLine); } }
/// <summary> /// Closes the appender and releases resources. /// </summary> virtual public void Close() { // Stop the previous asynchronous processing. if (_asyncStrategy != null) { // Append footer. if (!string.IsNullOrEmpty(_asyncLayout.Footer)) { _asyncStrategy.AddItem(_asyncLayout.Footer + Environment.NewLine); } _asyncStrategy.StopProcessing(); _asyncStrategy.Dispose(); _asyncStrategy = null; } // Close the asynchronous target appender. if (_asyncAppender != null) { _asyncAppender.Close(); _asyncAppender = null; } }