Esempio n. 1
0
        /// <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);
            }
        }
Esempio n. 2
0
 private void AppendInternal(LoggingEvent loggingEvent)
 {
     // Add the formatted logging message to the asynchronous strategy.
     _asyncStrategy.AddItem(_asyncLayout.Format(loggingEvent));
 }