public void WriteEvent(string eventName, LogEventSeverity eventSeverity = LogEventSeverity.Information, LogEventType eventType = LogEventType.ApplicationEvent, IEnumerable <KeyValuePair <string, object> > properties = null, string source = "", string sourceMethod = "") { if (!IsEnabled) { return; } using (var pooledLogEvent = _EntryPool.Take()) { var logEvent = pooledLogEvent.Value; logEvent.DateTime = _LogClock?.Now ?? DateTimeOffset.Now; logEvent.EventName = eventName ?? String.Empty; logEvent.EventSeverity = eventSeverity; logEvent.EventType = eventType; if (Utils.Any <KeyValuePair <string, object> >(properties)) { logEvent.Properties = new Dictionary <string, object>(); foreach (var property in properties) { logEvent.Properties[property.Key] = RenderProperty(property.Value); } } WriteEvent(logEvent, source, sourceMethod); } }
private static ConsoleColor GetConsoleColor(LogEventSeverity eventSeverity) { switch (eventSeverity) { case LogEventSeverity.CriticalError: case LogEventSeverity.FatalError: return(ConsoleColor.DarkRed); case LogEventSeverity.Error: return(ConsoleColor.Red); case LogEventSeverity.Debug: case LogEventSeverity.Diagnostic: return(ConsoleColor.Magenta); case LogEventSeverity.Verbose: return(ConsoleColor.DarkCyan); case LogEventSeverity.Warning: return(ConsoleColor.Yellow); default: return(ConsoleColor.Green); } }
private void WriteEventWithExplicitSource(string eventName, LogEventSeverity eventSeverity, LogEventType eventType, string source, string sourceMethod, int sourceLineNumber, KeyValuePair <string, object>[] properties, Exception exception) { try { if (!IsEnabled || !(_FirstChanceFilter?.ShouldLog(eventName, eventSeverity, eventType, source, sourceMethod) ?? true)) { return; } using (var pooledLogEvent = _EntryPool.Take()) { var logEvent = pooledLogEvent.Value; InitialiseLogEvent(eventName, eventSeverity, eventType, properties, exception, logEvent); UnsafeWriteEvent(logEvent, source, sourceMethod, sourceLineNumber); } } 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; } } }
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 LogEntry(LogEventSeverity Severity, string Message, string Source, Exception Exception) { if (string.IsNullOrWhiteSpace(Message)) { throw new ArgumentNullException("Message"); } if (Severity < LogEventSeverity.Debug || Severity > LogEventSeverity.Fatal) { throw new ArgumentOutOfRangeException("Severity"); } this.Severity = Severity; this.Message = Message; this.Source = Source; this.Exception = Exception; this.Depth = 0; }
public void WriteEventWithSource(string eventName, LogEventSeverity eventSeverity = LogEventSeverity.Information, LogEventType eventType = LogEventType.ApplicationEvent, Exception exception = null, #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, params KeyValuePair <string, object>[] properties) { WriteEventWithExplicitSource(eventName, eventSeverity, eventType, source, sourceMethod, sourceLineNumber, properties, exception); }
public LogSeverityFilter(LogEventSeverity requiredSeverity) { _RequiredSeverity = requiredSeverity; }
public MinimumLogSeverityFilter(LogEventSeverity minimumSeverity) { _MinimumSeverity = minimumSeverity; }
public LogEntry(LogEventSeverity Severity, string Message, Exception Exception) : this(Severity, Message, null, Exception) { }
public LogEntry(LogEventSeverity Severity, string Message, string Source) : this(Severity, Message, Source, null) { }
/// <summary> /// Returns true if the specified <see cref="LogEventSeverity"/> value is allowed based on the <see cref="MinimumSeverity"/> property. /// </summary> /// <param name="severity">The <see cref="LogEventSeverity"/> vaalue to test.</param> /// <returns>True if the severity provided is allowed by this switch (is at least the minimum level currently specified).</returns> public bool IsAllowed(LogEventSeverity severity) { return(severity >= _MinimumSeverity); }
/// <summary> /// Full constructor. /// </summary> /// <param name="minimumSeverity">The initial value for the <see cref="MinimumSeverity"/> property.</param> public LogEventSeveritySwitch(LogEventSeverity minimumSeverity) { _MinimumSeverity = minimumSeverity; }
/// <summary> /// <para>Returns a boolean indicating if an event should be logged based on some basic properties, known early in the logging process.</para> /// </summary> /// <param name="message">The message text for the event.</param> /// <param name="eventSeverity">The <see cref="LogEventSeverity"/> of the event.</param> /// <param name="eventType">The <see cref="LogEventType"/> for the event.</param> /// <param name="source">The string representation of the source of the event.</param> /// <param name="sourceMethod">The string representation of the source method requesting the event be logged.</param> /// <returns>A boolean, true if the event should be logged, else false.</returns> public bool ShouldLog(string message, LogEventSeverity eventSeverity, LogEventType eventType, string source, string sourceMethod) { return((_SeveritySwitch?.IsAllowed(eventSeverity) ?? true) && IsEventTypeAllowed(eventType)); }
public void WriteEvent(string eventName, LogEventSeverity eventSeverity, LogEventType eventType, Exception exception, params KeyValuePair <string, object>[] properties) { WriteEventWithExplicitSource(eventName, eventSeverity, eventType, null, null, -1, properties, exception); }
public void WriteEvent(string eventName, LogEventSeverity eventSeverity, LogEventType eventType, params KeyValuePair <string, object>[] properties) { WriteEvent(eventName, eventSeverity, eventType, null, properties); }
/// <summary> /// Writes a <see cref="LogEvent"/> to the appropriate output locations if it meets the configured filter. /// </summary> /// <param name="eventName">The event name or message to write to the log.</param> /// <param name="eventSeverity">A <see cref="LogEventSeverity"/> to assign to the written log entry. The default value is <see cref="LogEventSeverity.Information"/>.</param> public void WriteEvent(string eventName, LogEventSeverity eventSeverity) { WriteEvent(eventName, eventSeverity, null); }