Make the return value of LoggerConfiguration.CreateLogger()
concrete
#719
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR communicates the dispose requirement of the logging pipeline by returning a concrete disposable type,
Logger
, fromCreateLogger()
.One consequence is that
using
syntax can be applied:It's not anticipated that users will generally wrap logger creation in a
using
block however; rather in 2.0 theCloseAndFlush()
method will cover apps that base logging off of the staticLog
class.Doing this however clarifies at the API level that the logger needs to be flushed in some way. This is important as .NET Core doesn't expose any
AppDomain
unload-time hooks to trigger flushing, which historically we've relied on.See also #718, where working around this design issue has lead us astray.
Caveats
This regresses one minor point - a logger with no sinks configured is no longer switched for a
SilentLogger
behind the scenes; users relying on this behaviour instead need to avoid configuring the logger at all. The alternative - returning something that could be shared in common withSilentLogger
, would require one of the less-appealing options discussed in Alternatives below.Another caveat is that in order to prevent a public-surface-area explosion, the constructors of this type are internal. This should not be a significant issue as
ILogger
should be the interface used in application code.Alternatives
Instead of exposing the concrete
Logger
class, the following options were also available:ILoggingPipeline
or similar: disposable interfaces are a semantic wart since only implementations determine the need for disposal