You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to use this in a console application but found that if I logged and exited immediately then the log file was not flushed, there was no opportunity to specify the dispose.
I ended up doing the below in the end.
// Set up Serilog
Log.Logger = new LoggerConfiguration()
.WriteTo.RollingFile(logFilename)
.CreateLogger();
// Add logging
services.AddSingleton(
new LoggerFactory()
.AddSerilog(dispose:true)
.AddConsole(loggingConfiguration)
.AddDebug(LogLevel.Trace)
);
The text was updated successfully, but these errors were encountered:
Thanks for the heads-up, Daniel. I think dispose: true should be the default/only supported option using this package - if you or anyone out there would like to investigate and/or send a PR, any help here would be appreciated. Thanks!
I was then digging around the .NET source code and found this and this.
The code in the first link is called when using the ILoggingBuilder extension methods. I don't know why but disposing: false is enforced there, so my first code snipped could not work.
The code in the second link is called when using the ILoggerFactory extension methods. Here, disposing: true is enforced.
I tried to use this in a console application but found that if I logged and exited immediately then the log file was not flushed, there was no opportunity to specify the dispose.
I ended up doing the below in the end.
The text was updated successfully, but these errors were encountered: