如何在 .NET Core 3 中通过命令行参数设置日志级别

Sto*_*mov 2 .net-core-logging .net-core-configuration

我有一个 .NET Core 3.0 控制台应用程序。我有一个 Microsoft.Extensions.Logging 记录器,并且正在使用命令行参数构建 Microsoft.Extensions.Configuration。

我的问题是“如何通过命令行参数设置日志级别?”

Sto*_*mov 5

正如ASP.NET Core 文档中的配置中所指出的,参数可以通过以下方式之一传递:

No prefix   CommandLineKey1=value1
Two dashes  --CommandLineKey2=value2, --CommandLineKey2 value2
Slash (/)   /CommandLineKey3=value3,  /CommandLineKey3 value3
Run Code Online (Sandbox Code Playgroud)

例子:

No prefix   CommandLineKey1=value1
Two dashes  --CommandLineKey2=value2, --CommandLineKey2 value2
Slash (/)   /CommandLineKey3=value3,  /CommandLineKey3 value3
Run Code Online (Sandbox Code Playgroud)