예제 #1
0
        /// <summary>
        /// Queues the <paramref name="logEvent"/> for writing to the child log writers.
        /// </summary>
        /// <remarks>
        /// <para>Queues the item and also notifies the write thread to start work if queue size is at least equal to the configured batch size, otherwise starts/resets a timer to kick off the write thread after the configured timeout.</para>
        /// </remarks>
        /// <param name="logEvent">A <see cref="LogEvent"/> instance to write.</param>
        protected override void WriteEventInternal(LogEvent logEvent)
        {
#if !CONTRACTS_ONLY
            try
            {
                if (logEvent == null)
                {
                    throw new ArgumentNullException(nameof(logEvent));
                }

                CheckIsDisposed();

                var pooledEvent = _LogEventPool.Take();
                logEvent.Clone(pooledEvent.Value);

                _BufferedLogEvents.Enqueue(pooledEvent);
                if (_BufferedLogEvents.Count >= _BatchSize)
                {
                    SetWriteEventsSignal();
                }
                else
                {
                    StartTimeoutTimer();
                }
            }
            catch (LogException lex)
            {
                if (_ErrorHandler.ReportError(lex) == LoggingErrorPolicy.Rethrow)
                {
                    throw;
                }
            }
            catch (Exception ex) when(!ex.ShouldRethrowImmediately())
            {
                var wrappedException = new LogException(ex.Message, ex);

                if (_ErrorHandler.ReportError(wrappedException) == LoggingErrorPolicy.Rethrow)
                {
                    throw wrappedException;
                }
            }
#endif
        }
예제 #2
0
파일: Logger.cs 프로젝트: Yortw/ScribeSharp
        /// <summary>
        /// Writes a <see cref="LogEvent"/> to the appropriate output locations if it meets the configured filter.
        /// </summary>
        /// <param name="logEvent">The <see cref="LogEvent"/> instance containing data to write.</param>
        public void WriteEvent(LogEvent logEvent)
        {
            if (logEvent == null)
            {
                throw new ArgumentNullException(nameof(logEvent));
            }

            try
            {
                if (!IsEnabled || !(_FirstChanceFilter?.ShouldLog(logEvent.EventName, logEvent.EventSeverity, logEvent.EventType, logEvent.Source, logEvent.SourceMethod) ?? true))
                {
                    return;
                }

                UnsafeWriteEvent(logEvent, null, null, -1);
            }
            catch (LogException lex)
            {
                if (_ErrorHandler.ReportError(lex) == LoggingErrorPolicy.Rethrow)
                {
                    throw;
                }
            }
            catch (Exception ex) when(!ex.ShouldRethrowImmediately())
            {
                var wrappedException = new LogException(ex.Message, ex);

                if (_ErrorHandler.ReportError(wrappedException) == LoggingErrorPolicy.Rethrow)
                {
                    throw wrappedException;
                }
            }
        }