serilog / serilog-sinks-console

Write log events to System.Console as text or JSON, with ANSI theme support
Apache License 2.0
248 stars 72 forks source link

ConsoleSink class being internal #161

Open megasuperlexa opened 3 months ago

megasuperlexa commented 3 months ago

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.

nblumhardt commented 3 months ago

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!