Example #1
0
 /// <summary>
 /// Writes an event, but only if it passes the filter provided via the constructor.
 /// </summary>
 /// <param name="logEvent">The log event to write.</param>
 public void Write(LogEvent logEvent)
 {
     if (_Filter.ShouldProcess(logEvent))
     {
         _LogWriter.Write(logEvent);
     }
 }
Example #2
0
 /// <summary>
 /// Called by the system to ask this context provider to add any properties it wants to apply.
 /// </summary>
 /// <param name="logEvent">The <see cref="LogEvent"/> to add properties to.</param>
 /// <param name="typeRendererMap">A <see cref="ITypeRendererMap"/> that can be used to locate <see cref="IPropertyRenderer"/> instances to use when formatting properties. May be null if no renderers have been provided.</param>
 public void AddProperties(LogEvent logEvent, ITypeRendererMap typeRendererMap)
 {
     if ((_Filter?.ShouldProcess(logEvent) ?? true))
     {
         AddPropertiesCore(logEvent, typeRendererMap);
     }
 }
Example #3
0
        public void WriteEvent(LogEvent logEvent, string source = "", string sourceMethod = "")
        {
            if (!IsEnabled)
            {
                return;
            }

            if (logEvent == null)
            {
                throw new ArgumentNullException(nameof(logEvent));
            }

            if (logEvent.DateTime == DateTimeOffset.MinValue)
            {
                logEvent.DateTime = _LogClock?.Now ?? DateTimeOffset.Now;
            }

            if (String.IsNullOrWhiteSpace(logEvent.Source))
            {
                logEvent.Source = source;
            }
            if (String.IsNullOrWhiteSpace(logEvent.SourceMethod))
            {
                logEvent.SourceMethod = sourceMethod;
            }

            FillProperties(logEvent);

            if (logEvent.Properties == null)
            {
                logEvent.Properties = EmptyProperties;
            }

            if (_Filter?.ShouldProcess(logEvent) ?? true)
            {
                if (_LogWriter.RequiresSynchronisation)
                {
                    lock (this)
                    {
                        UnsynchronisedWrite(logEvent);
                    }
                }
                else
                {
                    UnsynchronisedWrite(logEvent);
                }
            }
        }
Example #4
0
 public void Write(LogEvent logEvent)
 {
     try
     {
         if (_Filter?.ShouldProcess(logEvent) ?? true)
         {
             WriteFilteredEvent(logEvent);
         }
     }
     catch (StackOverflowException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new LogWriterException(this, ex);
     }
 }
Example #5
0
 /// <summary>
 /// Returns a boolean indicating if the specified <see cref="LogEvent"/> instance should be written.
 /// </summary>
 /// <param name="logEvent">A <see cref="LogEvent"/> instance to analyse.</param>
 /// <returns>True if the log event should be written, false to ignore it.</returns>
 protected virtual bool ShouldLogEvent(LogEvent logEvent)
 {
     return(_Filter?.ShouldProcess(logEvent) ?? true);
 }