Closed BastienDurel closed 2 years ago
What did I miss ?
problem is in the initLogger
method:
using ILoggerFactory loggerFactory =
LoggerFactory.Create(builder =>
when method returns using
calls loggerFactory.Dispose
which finalizes all logging providers. For FileLoggerProvider Dispose
just closes the file and nothing will be written after that.
Console logger works because of it internals - it doesn't close anything after dispose. However, disposing LoggerFactory and using loggers after that is a very wrong usage of the logging infrastructure.
You're right, thank you. I copied this from the SimpleConsole documentation without knowing the using
keyword implies disposition.
Should I keep a reference on the factory, or letting it leave the scope without being disposed is OK ?
Hello,
I tried to use
AddFile(file, options => {})
to add a filte logger to my logger initialization, but this did not workThe log file is created, but nothing is written into it.
I pushed a minimalist project here : https://git.geekwu.org/bastien/test_log
I also tried to use the
loggerFactory.AddProvider(new FileLoggerProvider(file, true));
approch, but I got the same (non) resultWhat did I miss ?