Add/remove serilog logging level overrides at run time

588 Views Asked by At

I am using Serilog in .Net 6 WebApi and the required serilog settings, including default logging level and few overrides, are currently being set via appsettings. However, I am looking for a way to dynamically add/remove logging level override for additional namespaces during runtime so that I can capture additional logs on demand for troubleshooting issues, without redeploying the application with setting changes. Is this possible? Any guidance available on how this can be achieved?

Thanks!

1

There are 1 best solutions below

3
On

You can implement a custom configuration provider in .NET Core which reads the configuration from Database. And you may need to implement Reload option as well. So when you update the database - your configuration will get updated. Here are some references which may help you.

  1. Implement a custom configuration provider in .NET
  2. A Refreshable SQL Server Configuration Provider for .NET Core
  3. Creating a custom ConfigurationProvider for a Entity Framework Core source