/// <summary> /// Formats the given <see cref="ILoggerStructure"/> and writes a verbose log message. /// </summary> /// <param name="logger">The <see cref="ILogger"/> to write to.</param> /// <param name="state">The <see cref="ILoggerStructure"/> to write.</param> /// <param name="error">The exception to log.</param> public static void WriteVerbose( [NotNull] this ILogger logger, ILoggerStructure state, Exception error = null) { logger.Write(LogLevel.Verbose, state, error); }
/// <summary> /// Formats the given <see cref="ILoggerStructure"/> and writes a critical log message. /// </summary> /// <param name="logger">The <see cref="ILogger"/> to write to.</param> /// <param name="state">The <see cref="ILoggerStructure"/> to write.</param> /// <param name="error">The exception to log.</param> public static void WriteCritical( [NotNull] this ILogger logger, ILoggerStructure state, Exception error = null) { logger.Write(LogLevel.Critical, state, error); }
/// <summary> /// Formats the given <see cref="ILoggerStructure"/> and writes a warning log message. /// </summary> /// <param name="logger">The <see cref="ILogger"/> to write to.</param> /// <param name="state">The <see cref="ILoggerStructure"/> to write.</param> /// <param name="error">The exception to log.</param> public static void WriteWarning( [NotNull] this ILogger logger, ILoggerStructure state, Exception error = null) { logger.Write(LogLevel.Warning, state, error); }
/// <summary> /// Formats the given <see cref="ILoggerStructure"/> and writes an informational log message. /// </summary> /// <param name="logger">The <see cref="ILogger"/> to write to.</param> /// <param name="state">The <see cref="ILoggerStructure"/> to write.</param> /// <param name="error">The exception to log.</param> public static void WriteInformation( [NotNull] this ILogger logger, ILoggerStructure state, Exception error = null) { logger.Write(LogLevel.Information, state, error); }
//------------------------------------------HELPERS------------------------------------------// private static void Write( this ILogger logger, LogLevel logLevel, ILoggerStructure state, Exception exception = null) { logger.Write(logLevel, 0, state, exception, _loggerStructureFormatter); }
/// <summary> /// Formats the given <see cref="ILoggerStructure"/> and writes a critical log message. /// </summary> /// <param name="logger">The <see cref="ILogger"/> to write to.</param> /// <param name="eventId">The event id associated with the log.</param> /// <param name="state">The <see cref="ILoggerStructure"/> to write.</param> /// <param name="error">The exception to log.</param> public static void WriteCritical( [NotNull] this ILogger logger, int eventId, ILoggerStructure state, Exception error = null) { logger.WriteWithEvent(LogLevel.Critical, eventId, state, error); }
private static void WriteWithEvent( this ILogger logger, LogLevel logLevel, int eventId, ILoggerStructure state, Exception exception = null) { logger.Write(logLevel, eventId, state, exception, _loggerStructureFormatter); }
private static string LoggerStructureFormatter(ILoggerStructure state, Exception exception) { return(state.Format() + Environment.NewLine + exception); }
public StructureEnricher(ILoggerStructure structure) { _structure = structure; }
private void FormatLoggerStructure(StringBuilder builder, ILoggerStructure structure, int level, bool bullet) { if (structure.Message != null) { builder.Append(structure.Message); } var values = structure.GetValues(); if (values == null) { return; } var isFirst = true; foreach (var kvp in values) { builder.AppendLine(); if (bullet && isFirst) { builder.Append(' ', level * _indentation - 1) .Append('-'); } else { builder.Append(' ', level * _indentation); } builder.Append(kvp.Key) .Append(": "); if (kvp.Value is IEnumerable && !(kvp.Value is string)) { foreach (var value in (IEnumerable)kvp.Value) { if (value is ILoggerStructure) { FormatLoggerStructure( builder, (ILoggerStructure)value, level + 1, bullet: true); } else { builder.AppendLine() .Append(' ', (level + 1) * _indentation) .Append(value); } } } else if (kvp.Value is ILoggerStructure) { FormatLoggerStructure( builder, (ILoggerStructure)kvp.Value, level + 1, bullet: false); } else { builder.Append(kvp.Value); } isFirst = false; } }