serilog-sinks-console icon indicating copy to clipboard operation
serilog-sinks-console copied to clipboard

ConsoleSink class being internal

Open megasuperlexa opened this issue 1 year ago • 1 comments

Hello, what is the reason for making the ConsoleSink class internal? I am writing my own ad-hoc limiting sink and cannot make use of ConsoleSink because it cannot be instantiated and passed inside my sink.
I have no problems with GraylogSink because it is public, so I propose to make ConsoleSync public too.

megasuperlexa avatar Aug 16 '24 07:08 megasuperlexa

Hi! Instead of constructing the sink directly, use LoggerSinkConfiguration.Wrap(..:

var limitingSink = LoggerSinkConfiguration.Wrap(
    enclosed => new LimitingSink(enclosed),
    wt => wt.Console());

This will work with all existing Serilog sinks, and automatically handles correct IDisposable and IAsyncDisposable forwarding to the wrapped sink (removing the need to implement these on your wrapper sink type).

See also https://github.com/serilog/serilog/pull/2060 - HTH!

nblumhardt avatar Aug 16 '24 22:08 nblumhardt