Closed Driedas closed 7 years ago
Thanks for the note!
In Serilog.Extensions.Logging we provide a similar option via the dispose
flag:
Could we do something similar here?
Sure, that's another option.
If dispose: true is passed in, Autofac will assume ownership of the dependency and instead of .ExternallyOwned()
the Log.Logger
would get registered as .SingleInstance().OnRelease(logger => Log.CloseAndFlush())
right?
@Driedas yes, I think that's the way it would work 👍
Closed by #20 - will be published in a -dev-
package by CI shortly. Thanks @Driedas !
Thanks, 't was a lot of fun working on this, appreciate your input and time spent reviewing :-) And thanks for the awesomest logging library out there!
Hey, I really like the idea of this module for enriching log entries, however I have one issue with it - where to call Log.CloseAndFlush(). The module specifies the dependency as ExternallyOwned, however if in a project an ILogger instance is always retrieved via Autofac, I would like it to handle the Disposal as well (not relying on Application_End, etc).
How about adding a generic Lambda Action as another parameter to the SerilogContainerBuilderExtensions.RegisterLogger extension method, that would allow something like this:
In order to be backwards compatible, the parameter would be nullable, and the default Action would specify the dependency as being .ExternallyOwned().
If you agree and like this approach, I can submit a PR with this change...