Initialization loggerFactory limitations
See original GitHub issueIs your feature request related to a problem? Please describe.
Currently some IHostBuilder
extensions methods (e.g. AddKubernetesConfiguration()
, AddConfigServer()
) accepts an optional ILoggerFactory
.
Because this code is evaluated before the DynamicSerilogProvider is created, the loggerFactory can only be configured using a static serilog configuration, i.e. its log level cannot be changed at runtime and cannot be configured from appsettings.
//create loggerFactory from a static configuration (not ideal)
ILoggerFactory initLogFactory = new LoggerFactory().AddSerilog(new LoggerConfiguration().MinimumLevel.Error().WriteTo.Console().CreateLogger());
return Host.CreateDefaultBuilder(args)
.AddDynamicSerilog()
.AddKubernetesConfiguration(null, initLogFactory) //initLogFactory is not configured with DynamicSerilog
.AddConfigServer(initLogFactory) //initLogFactory is not configured with DynamicSerilog
.AddDiscoveryClient()
.AddAllActuators()
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
Describe the solution you’d like
I would like to be able to pass loggerFactory in a lazy manner, so that I can build it when the DynamicSerilog is available. If that is not possible maybe those extension method may avoid to receive a loggerFactory as parameter, andthey could take it using DI instead (is it possible?).
Describe alternatives you’ve considered
Use a static Serilog LoggerConfiguration
.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
java - What's the best way to initialise a logger in a class?
I've got two options to initialise a Logger within a class. The first way is providing an instance of the Class<?> : logger...
Read more >SLF4J FAQ
More specifically, when initializing the LoggerFactory class will no longer search for the StaticLoggerBinder class on the class path.
Read more >.NET Core Logging With LoggerFactory: Best Practices and ...
1. You could pass your existing LoggerFactory into every object/method you call (which is a terrible idea). 2. You could create your own...
Read more >During testing, you must initialize the static LoggerFactory.
It strong limitations. "For the other presentation layers, you have to implement a startup logic anyway, where you then have to add the...
Read more >Logging in .NET Core and ASP.NET Core
To control costs and not exceed data storage limits, log Trace , Debug , or Information level messages to a high-volume, low-cost data...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@DaviGia To clarify, the requirement has to do with the ILoggerFactory respecting the available configuration and not with the dynamically changing the log level via actuators. If you have a sample with the other config sources you mention that will be great.
@DaviGia I am wondering what the use case for this is. The logFactory is only used in the build phase. So your app is not ready and available for you to change configuration dynamically. Can you please clarify? Is it that it cannot be configured from app settings?