-
Notifications
You must be signed in to change notification settings - Fork 829
Closed
Labels
Description
Is your feature request related to a problem? Please describe.
I have a quite complex logging pipeline having at least two levels of nesting via configuration.WriteTo.Logger(nestedLogger)
. The problem is, I can't dispose all of it in one go, because nested loggers are not disposed when parent logger is.
Describe the solution you'd like
I would like to be able to specify that I want nested logger to be disposed with the pipeline, i.e.:
configuration.WriteTo.Logger(nestedLogger, dispose: true)
This can be easily accomplished by passing the flag down to SecondaryLoggerSink
.
Describe alternatives you've considered
WriteTo.Logger(Action<LoggerConfiguration>)
which creates logger internally and disposes of it.
I was able to replace only on of my usages with this one, because in other cases the logger is already created.WriteTo.Sink(logger)
(using the fact thatSerilog.Core.Logger
is actually aILogEventSink
).
This way the events pushed to logger are not copied so they can (and will be, in my case) modified by nested logger's enrichment. Also, feels hack-ish and requires access toLogger
instead ofILogger
.WriteTo.Logger(lc => lc.WriteTo.Sink(logger))
.
This, probably, will work (and I might settle for this in a short-term), but, same as above, requires access toLogger
and feels even more hack-ish.
BTW, I'd add a simple overload in my own code, but both SecondaryLoggerSink
and LogEvent.Copy
are internal
.