public void CreatingWithoutAsyncCreatesColoredConsoleTarget() { ConsoleLoggerOptions options = CreateLoggerOptions(LogFormat.Plain, async: false); LoggingConfiguration config = _factory.Create(options); config.AllTargets.First().Should().BeOfType <ColoredConsoleTarget>(); }
public void CreatingWithAsyncCreatesAsyncTargetWrapper() { ConsoleLoggerOptions options = CreateLoggerOptions(LogFormat.Plain, async: true); LoggingConfiguration config = _factory.Create(options); config.AllTargets.First().Should().BeOfType <AsyncTargetWrapper>(); }
public void CreatingWithPlainFormatSetsPlainLayout() { ConsoleLoggerOptions options = CreateLoggerOptions(LogFormat.Plain, async: false); LoggingConfiguration config = _factory.Create(options); ColoredConsoleTarget target = config.AllTargets.OfType <ColoredConsoleTarget>().First(); target.Layout.Should().BeOfType <PlainLayout>(); }
private static void SetupNlogConfig(ConsoleLoggerOptions options) { LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging"))); LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging.Abstractions"))); LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("NLog.Extensions.Logging"))); LogManager.AddHiddenAssembly(typeof(ConsoleLoggerConfigureExtensions).GetTypeInfo().Assembly); LogManager.Configuration = new NlogConfigurationFactory().Create(options); LogManager.Configuration.Reload(); LogManager.ReconfigExistingLoggers(); }
public LoggingConfiguration Create(ConsoleLoggerOptions loggingOptions) { var nlogConfig = new LoggingConfiguration(); Target nlogTarget = CreateConsoleTarget(loggingOptions); if (loggingOptions.Async) { nlogTarget = new AsyncTargetWrapper(TARGET_ASYNC_CONSOLE, nlogTarget); } nlogConfig.AddTarget(nlogTarget); nlogConfig.AddRule(LogLevel.Trace, LogLevel.Fatal, nlogTarget); return(nlogConfig); }
/// <summary> /// Adds a console logger with the given <paramref name="options"/> to the <paramref name="factory"/>. /// </summary> public static ILoggerFactory AddAxoomConsole([NotNull] this ILoggerFactory factory, [NotNull] ConsoleLoggerOptions options) { if (factory == null) { throw new ArgumentNullException(nameof(factory)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } SetupLayoutRenderers(); factory.AddNLog(); SetupNlogConfig(options); return(factory); }
/// <summary> /// Adds a console logger with the given <paramref name="options"/> to the <paramref name="builder"/>. /// </summary> public static ILoggingBuilder AddAxoomConsole([NotNull] this ILoggingBuilder builder, [NotNull] ConsoleLoggerOptions options) { SetupLayoutRenderers(); builder.AddNLog(); SetupNlogConfig(options); return(builder); }
private static ColoredConsoleTarget CreateConsoleTarget(ConsoleLoggerOptions loggingOptions) => new ColoredConsoleTarget(name: TARGET_CONSOLE) { Layout = loggingOptions.Format.GetLayout(loggingOptions.IncludeMappedDiagnosticContext) };