/// <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); }
private void InitialiseLogEvent(string eventName, LogEventSeverity eventSeverity, LogEventType eventType, KeyValuePair <string, object>[] properties, Exception exception, LogEvent logEvent) { logEvent.DateTime = _LogClock.Now; logEvent.EventName = eventName ?? String.Empty; logEvent.EventSeverity = eventSeverity; logEvent.EventType = eventType; logEvent.Exception = exception; RenderProperties(properties, logEvent); }
public void WriteEventWithSource(LogEvent logEvent, #if SUPPORTS_CALLERATTRIBUTES [System.Runtime.CompilerServices.CallerFilePath] #endif string source = null, #if SUPPORTS_CALLERATTRIBUTES [System.Runtime.CompilerServices.CallerMemberName] #endif string sourceMethod = null, #if SUPPORTS_CALLERATTRIBUTES [System.Runtime.CompilerServices.CallerLineNumber] #endif int sourceLineNumber = -1, bool cloneEvent = false) { 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; } LogEvent eventToWrite = logEvent; PooledObject <LogEvent> pooledLogEvent = null; try { if (cloneEvent) { pooledLogEvent = _EntryPool.Take(); logEvent.Clone(pooledLogEvent.Value); eventToWrite = pooledLogEvent.Value; } if (eventToWrite.DateTime == DateTimeOffset.MinValue) { eventToWrite.DateTime = _LogClock.Now; } UnsafeWriteEvent(eventToWrite, source, sourceMethod, sourceLineNumber); } finally { if (cloneEvent && pooledLogEvent != null) { pooledLogEvent.Dispose(); } } } 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; } } }