dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.18k stars 4.72k forks source link

LogLevel at runtime #50035

Open ducalai opened 4 years ago

ducalai commented 4 years ago

We have a scenario where our application should get its logging LogLevel configuration using an API. Then, we would like to set it at runtime. I know Serilog supports it using LoggingLevelSwitch, but how to solve it directly in Microsoft.Extensions.Logging? If not possible now, are you planning to support it?

gfoidl commented 4 years ago

You can create / update the Configuration with the values from the mentioned API before building the host.

ducalai commented 4 years ago

So, in Program.cs using .ConfigureLogging(this IWebHostBuilder hostBuilder, Action<WebHostBuilderContext, ILoggingBuilder> configureLogging) extension method? Once host is created, it is no more possible?

analogrelay commented 4 years ago

Logging monitors config for changes and reloads, so if your configuration source supports reloading (such as the built-in JSON one), then changing the file will automatically trigger a reload and reconfiguration of logging without requiring a restart of the app.

AwesomeYuer commented 4 years ago

dynamic seting ILogger's LogLevel at runtime is very very useful @anurse

ghost commented 3 years ago

Tagging subscribers to this area: @maryamariyan See info in area-owners.md if you want to be subscribed.

Issue Details
We have a scenario where our application should get its logging `LogLevel` configuration using an API. Then, we would like to set it at runtime. I know Serilog supports it using `LoggingLevelSwitch`, but how to solve it directly in Microsoft.Extensions.Logging? If not possible now, are you planning to support it?
Author: ducalai
Assignees: -
Labels: `area-Extensions-Logging`, `untriaged`
Milestone: -