How to set log levels via command line arguments in .NET Core 3

3.1k views Asked by At

I have a .NET Core 3.0 console application. I have a Microsoft.Extensions.Logging logger and I'm building Microsoft.Extensions.Configuration using a command line arguments.

My question is "How can I set the log levels via command line arguments?"

1

There are 1 answers

0
Stoyan Dimov On BEST ANSWER

As pointed out in the Configuration in ASP.NET Core docs the arguments can be passed in one of the following ways:

No prefix   CommandLineKey1=value1
Two dashes  --CommandLineKey2=value2, --CommandLineKey2 value2
Slash (/)   /CommandLineKey3=value3,  /CommandLineKey3 value3

Example:

# Setting Warning level for all microsoft types
dotnet your.dll --Logging:LogLevel:Microsoft=Warning

# or setting Information level for your own types
dotnet run /Logging:LogLevel:YourNamespace:YourType Information