According to documentation, when an application is shutting down, it is recommended to dispose of Serilog using either
Log.CloseAndFlush();
or in case you have an instance variable to .CreateLogger()
, call its
.Dispose();
When building ASP.NET Core app in Visual Studio, it generates Program
and Startup
classes, neither of which implements IDisposable
. Are we supposed to add this interface to Program
so that we have a way to dispose Serilog directly?
As far as I know, ASP.NET calls into dispose of the logger providers and so its the responsibility of the individual providers to do any clean up.
But looks like Serilog's logger provider does not do anything in its dispose method: https://github.com/serilog/serilog-extensions-logging/blob/master/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerProvider.cs
I would suggest to post a question on the Serilog's repo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With