Closed sam-wheat closed 1 month ago
In my opinion, your logs not flushing before application exit. If you don't want to use static Log class you should call the dispose method for your logger.
@cancakar35 your opinion is spot on. Makes sense that Log.CloseAndFulsh()
is not going to work.
Thanks.
I spent all day chasing my tail wondering why logging to my db was not working. Turns out that if
Log.Logger
is not assigned, logging to the database does not work. IDK if this is by design or not. It is confusing that console logging works but not database logging, which led me to needlessly troubleshoot the database logging configuration.This search leads me to believe I should not need to set
Log.Logger
.The reason I create a logger object is because I inject
Microsoft.Extenions.Logging.ILogger
into a service library I use. The top level apps that depends on this library do not require logging to a database - only the library logs to the database. For this reason I did not want to assign to staticLog.Logger
- I want to inject a keyed instance of logger into my library so only it will log to the database.I show the code above to demonstrate why I need a keyed logger object versus static
Log.Logger
. Perhaps I am overthinking it? In any case, here is a console app that replicates the problem with not assigning toLog.Logger
:Serilog versions
OS is Windows, Target framework is net 8.