NetEscapades.Extensions.Logging icon indicating copy to clipboard operation
NetEscapades.Extensions.Logging copied to clipboard

Generic Host Builder calls Dispose on LoggerFactory

Open endintiers opened this issue 4 years ago • 1 comments

HostBuilder is now calling Dispose on its ILoggerFactory after building all the loggers (a bug fix I think) which is in turn disposing the BatchingLoggerProvider which is stopping the logging at startup - so, it no longer works.

The glass is cloudy but I think you have to pass a factory to the ILoggerFactory instead of letting it build the class automagically, so something like: builder.Services.AddSingleton<ILoggerProvider, FileLoggerProvider>(factory => { return new FileLoggerProvider(); }); instead of: builder.Services.AddSingleton<ILoggerProvider, FileLoggerProvider>();

Because if you build it YOURSELF, then Dispose doesn't get called by the container... But the first doesn't work because of options....

endintiers avatar Jul 15 '20 02:07 endintiers

Dispose doesn't get called by the container Which confusingly seems to be the container of the ILoggerFactory, not the Host Container. When you do it this way the LoggerProvider still gets Disposed by the Host Container... I think there are multiple containers.

endintiers avatar Jul 15 '20 07:07 endintiers