Пример #1
0
        /// <summary>
        /// Configure the console logger and set it to filter logs not related to the fullnode.
        /// </summary>
        /// <param name="loggerFactory">The logger factory to add the console logger.</param>
        /// <returns>The new console settings.</returns>
        public static void AddConsoleWithFilters(this ILoggerFactory loggerFactory)
        {
            ConsoleLoggerSettings consoleLoggerSettings = new ConsoleLoggerSettings
            {
                Switches =
                {
                    { "Default",              Microsoft.Extensions.Logging.LogLevel.Information },
                    { "System",               Microsoft.Extensions.Logging.LogLevel.Warning     },
                    { "Microsoft",            Microsoft.Extensions.Logging.LogLevel.Warning     },
                    { "Microsoft.AspNetCore", Microsoft.Extensions.Logging.LogLevel.Error       }
                }
            };

            ConsoleLoggerProvider consoleLoggerProvider = new ConsoleLoggerProvider(consoleLoggerSettings);

            loggerFactory.AddProvider(consoleLoggerProvider);

            ExtendedLoggerFactory extendedLoggerFactory = loggerFactory as ExtendedLoggerFactory;

            Guard.NotNull(extendedLoggerFactory, nameof(extendedLoggerFactory));
            extendedLoggerFactory.ConsoleLoggerProvider = consoleLoggerProvider;
            extendedLoggerFactory.ConsoleSettings       = consoleLoggerSettings;
        }