Exemple #1
0
        public void CreatingWithoutAsyncCreatesColoredConsoleTarget()
        {
            ConsoleLoggerOptions options = CreateLoggerOptions(LogFormat.Plain, async: false);

            LoggingConfiguration config = _factory.Create(options);

            config.AllTargets.First().Should().BeOfType <ColoredConsoleTarget>();
        }
Exemple #2
0
        public void CreatingWithAsyncCreatesAsyncTargetWrapper()
        {
            ConsoleLoggerOptions options = CreateLoggerOptions(LogFormat.Plain, async: true);

            LoggingConfiguration config = _factory.Create(options);

            config.AllTargets.First().Should().BeOfType <AsyncTargetWrapper>();
        }
Exemple #3
0
        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>();
        }
Exemple #4
0
 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);
        }
Exemple #6
0
        /// <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);
        }
Exemple #7
0
        /// <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)
 };