How to set minimum logging level uniformly for MS Logger and LoggerFactory

52 views Asked by At

I noticed it when working with server part of Blazor WebAsm app but I guess in general it applies to any ASP.Net app.

When I run my app (WebApplication) its Logger is set with minimal logging level based on configuration file.

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",

So currently it would be "Information", if I change it for example "Critical" it would be "Critical".

This works as expected, however within DI there is registered singleton LoggerFactory. It also has minimum logging level and it is not read from configuration file -- i.e. no matter what I write in config file, it remains "Information" (*).

I can change LoggerFactory (but not app.Logger) logging level with:

 services.AddLogging(options =>
        {
            options.SetMinimumLevel(...);
            ...

but it would require from me to extract logging level manually from config file. It does not look promising.

Is there one, single, uniform way to apply logging level from configuration both for app.Logger and LoggingFactory?

(*) Yes, I know about additional Development/Release config, this does not affect this problem.

0

There are 0 answers