/// <summary> /// Creates an instance of <see cref="ConsoleLoggerProvider"/>. /// </summary> /// <param name="options">The options to create <see cref="ConsoleLogger"/> instances with.</param> /// <param name="formatters">Log formatters added for <see cref="ConsoleLogger"/> insteaces.</param> public ConsoleLoggerProvider(IOptionsMonitor <ConsoleLoggerOptions> options, IEnumerable <ConsoleFormatter>?formatters) { _options = options; _loggers = new ConcurrentDictionary <string, ConsoleLogger>(); SetFormatters(formatters); IConsole?console; IConsole?errorConsole; if (DoesConsoleSupportAnsi()) { console = new AnsiLogConsole(); errorConsole = new AnsiLogConsole(stdErr: true); } else { console = new AnsiParsingLogConsole(); errorConsole = new AnsiParsingLogConsole(stdErr: true); } _messageQueue = new ConsoleLoggerProcessor( console, errorConsole, options.CurrentValue.QueueFullMode, options.CurrentValue.MaxQueueLength); ReloadLoggerOptions(options.CurrentValue); _optionsReloadToken = _options.OnChange(ReloadLoggerOptions); }
public ConsoleLogger(string name, Func <string, LogLevel, bool> filter, bool includeScopes) { if (name == null) { throw new ArgumentNullException(nameof(name)); } Name = name; Filter = filter ?? ((category, logLevel) => true); IncludeScopes = includeScopes; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Console = new WindowsLogConsole(); } else { Console = new AnsiLogConsole(new AnsiSystemConsole()); } }
public ConsoleLogger(string name, Func <string, LogLevel, bool> filter, bool includeScopes) { if (name == null) { throw new ArgumentNullException(nameof(name)); } Name = name; Filter = filter ?? ((category, logLevel) => true); IncludeScopes = includeScopes; if (PlatformServices.Default.Runtime.OperatingSystem.Equals("Windows", StringComparison.OrdinalIgnoreCase)) { Console = new WindowsLogConsole(); } else { Console = new AnsiLogConsole(new AnsiSystemConsole()); } }
internal ConsoleLogger(string name, Func <string, LogLevel, bool> filter, IExternalScopeProvider scopeProvider, ConsoleLoggerProcessor loggerProcessor) { if (name == null) { throw new ArgumentNullException(nameof(name)); } Name = name; Filter = filter ?? ((category, logLevel) => true);//filter为null时直接返回true,即不进行过滤 ScopeProvider = scopeProvider; _queueProcessor = loggerProcessor; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Console = new WindowsLogConsole();//*********************************在这里实例化一个Windows平台的System.Console !****************** } else { Console = new AnsiLogConsole(new AnsiSystemConsole()); } }
internal ConsoleLogger(string name, Func <string, LogLevel, bool> filter, IExternalScopeProvider scopeProvider, ConsoleLoggerProcessor loggerProcessor) { if (name == null) { throw new ArgumentNullException(nameof(name)); } Name = name; Filter = filter ?? ((category, logLevel) => true); ScopeProvider = scopeProvider; LogToStandardErrorThreshold = LogLevel.None; _queueProcessor = loggerProcessor; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Console = new WindowsLogConsole(); ErrorConsole = new WindowsLogConsole(stdErr: true); } else { Console = new AnsiLogConsole(new AnsiSystemConsole()); ErrorConsole = new AnsiLogConsole(new AnsiSystemConsole(stdErr: true)); } }