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

Filter only Error and Fatal to Event Log

Open timreynolds-53 opened this issue 5 years ago • 1 comments

It looks like The Windows.EventLog sink has no way of "ignoring" non error logs. Could an override be allowed to set a minimumLogEventToWrite="Information" for the default value, but allow it to be set to "Warning, Error, or Fatal"? I would like to have logs sent to multiple sinks (we currently use RollingFile and SEQ), but I would also like for Errors to go to a permanent home - AKA the Windows Event Log so our network folks have one place to look for serious issues.

Thanks - this is a GREAT product!

timreynolds-53 avatar Oct 14 '19 20:10 timreynolds-53

Before configuring your .WriteTo.EventLog(...) use the serilog extensions to Filter like so:

.Filter.ByIncludingOnly(evt => evt.Level != LogEventLevel.Error && evt.Level != LogEventLevel.Fatal) .WriteTo.EventLog(.....)

the-zack-stack avatar Jul 13 '20 21:07 the-zack-stack