Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Logging NetCore 3.1事件日志不会写入信息或调试消息_Logging_Asp.net Core 3.1 - Fatal编程技术网

Logging NetCore 3.1事件日志不会写入信息或调试消息

Logging NetCore 3.1事件日志不会写入信息或调试消息,logging,asp.net-core-3.1,Logging,Asp.net Core 3.1,我正在尝试使用NetCore 3.1的内置日志向Windows事件日志发送信息消息 我已经在我的appsettings.json中包含了一个默认日志级别为Debug的EventLog部分,并且在配置日志记录时还提供了一个过滤器。尽管如此,我只能在事件日志中看到错误和警告消息。这就好像我对LogLevel默认警告的覆盖被忽略了一样 有人知道我做错了什么吗 在appsettings.json中: "EventLog": { "LogLevel": { "Default": "

我正在尝试使用NetCore 3.1的内置日志向Windows事件日志发送信息消息

我已经在我的appsettings.json中包含了一个默认日志级别为Debug的EventLog部分,并且在配置日志记录时还提供了一个过滤器。尽管如此,我只能在事件日志中看到错误和警告消息。这就好像我对LogLevel默认警告的覆盖被忽略了一样

有人知道我做错了什么吗

在appsettings.json中:

  "EventLog": {
    "LogLevel": {
      "Default": "Debug",
      "Microsoft.Hosting.Lifetime": "Debug"
    }
  },
在program.cs中:

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
            .ConfigureLogging(
                logging =>
                {
                    logging.SetMinimumLevel(LogLevel.Debug);
                    logging.ClearProviders();
                    logging.AddFilter("Microsoft", LogLevel.Warning);
                    logging.AddConsole();
//#if !DEBUG
                    logging.AddEventLog(
                        eventLog =>
                        {
                            eventLog.SourceName = SERVICE_NAME;
                            eventLog.Filter =
                                (source, level) => level >= LogLevel.Debug;
                        }
                    );
//#endif
                }
            )
而且:

        _logger.LogError("This is a test error upon startup. Please do not be alarmed.  It should be followed by Warning, Information and Debug.");
        _logger.LogWarning("This is a test warning upon startup. Please do not be alarmed.  It should be followed by Information and Debug.");
        _logger.LogInformation("This is a information message upon startup.  It should be followed by Debug.");
        _logger.LogInformation("This is a debug message upon startup.  It should be last in a series of four.");
从事件日志中:

Warning 5/8/2020 2:36:56 PM SERVICE_NAME    0   None (This is a test warning upon startup. Please do not be alarmed.  It should be followed by Information and Debug.)
Error   5/8/2020 2:36:56 PM SERVICE_NAME    0   None (This is a test error upon startup. Please do not be alarmed.  It should be followed by Warning, Information and Debug.)
但不是其他两条预期的消息