Search code examples
.netlog4netserilog

Is there a SeriLog equivalent of log4net's BufferingForwardingAppender for detailed logging only on warning/error?


Is there a way in Serilog to setup a (limited size) log-buffer that collects all log events of a specified level and above (i.e. DEBUG) but does not log them into the target sink unless a certain higher level event happens (i.e. WARNING)?

Basically I'm asking if there is a way to replicate the BufferingForwardingAppender functionality from log4net.


Solution

  • Serilog doesn't have an equivalent of Log4Net's BufferingForwardingAppender out-of-the-box as of this writing, but there are some sinks built by the community that might be useful:

    Alternatively it should be easy to create your own Sink to implement that behavior.

    In that case you might want to look at the code of Serilog.Sinks.Async for inspiration, as it shows you a way of wrapping multiple sinks into one which would give you the opportunity for buffering the log messages before forwarding to the sinks.

    Finally, because you're familiar with Log4Net, you can integrate Log4Net with Serilog and use Log4Net's BufferingForwardingAppender by using the Log4Net Serilog Sink.