Closed
Description
I've got .netcore31 application (both a generic host and ASP.NET) application where a logger is throwing an exception when using the reloadable logger. I haven't developed a minimum test case, but it may have to do with static loggers being accessed early in the lifetime. The pattern is as follows:
- Create a class with a static logger (private static ILogger _log = Log.ForContext();
- Add another static method/property to the class, call a log method (i.e. _log.Debug) in the method.
- Add a non-static method that calls three log methods (i.e. _log.Debug x3)
- During services initialization, call the static method
- Initialize the CreateBootstrapLogger/UseSerilog as normal
- In the worker, get an instance of the class and call the non-static method.
- The first log method will succeed, as will the second
- The third throws an exception, because _cached is somehow null but _frozen is true (so it's trying to directly call the _cached logger)
If I get some time, I'll try to get a minimum reproducible example written, but I'm under some tight work deadlines at the moment. Hopefully the description above will help find the logic issue. Presumably, _cached = null and _frozen = true should never happen.