ConsoleLoggerOptions 上已过时的属性

Microsoft.Extensions.Logging.Console.ConsoleLoggerFormat 类型和 ConsoleLoggerOptions 上的一些属性现在已过时。

更改说明

从 .NET 5 开始,Microsoft.Extensions.Logging.Console.ConsoleLoggerFormat 类型和 ConsoleLoggerOptions 上的很多属性已过时。 已过时的属性是:

随着新的格式化程序的引入,这些属性现在单独的格式化程序上可用。

更改原因

Format 属性是枚举类型,不能表示自定义格式化程序。

其余属性是在 ConsoleLoggerOptions 上设置的,应用于控制台日志的这两种内置格式。 但是,由于引入了新的格式化程序 API,在特定于格式化程序的选项上表示格式更加有意义。 这项更改可更好地区分记录器和记录器格式化程序。

引入的版本

5.0

以下两个 JSON 代码片段显示了配置文件的更改方式。 旧配置文件:

{
  "Logging": {
    "LogLevel": {
      "Default": "None",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    },

    "Console": {
      "LogLevel": {
        "Default": "Information"
      },
      "Format": "Systemd",
      "IncludeScopes": true,
      "TimestampFormat": "HH:mm:ss",
      "UseUtcTimestamp": true
    }
  },
  "AllowedHosts": "*"
}

新配置文件:

{
  "Logging": {
    "LogLevel": {
      "Default": "None",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    },

    "Console": {
      "LogLevel": {
        "Default": "Information"
      },
      "FormatterName": "Systemd",
      "FormatterOptions": {
        "IncludeScopes": true,
        "TimestampFormat": "HH:mm:ss",
        "UseUtcTimestamp": true
      }
    }
  },
  "AllowedHosts": "*"
}

受影响的 API