Filtering events

Prerequisites:

Filtering allows a particular ILog instance to only record a subset of incoming log events. Events can be filtered by level, properties or literally any other information present.

Filter by level

Set a minimum allowed log level (events of lower levels will be dropped):

log = log.WithMinimumLevel(LogLevel.Warn);

Selectively disable some log levels:

log = log.WithDisabledLevels(LogLevel.Debug, LogLevel.Fatal);

Filter by a single property

Select events having a property with given name and a of given type value satisfying a predicate:

log = log.WithEventsSelectedByProperty<string>("prop", value => value == "foo");

Drop events having a property with given name and a value of given type satisfying a predicate:

log = log.WithEventsDroppedByProperty<string>("prop", value => value == "foo");

Filter by all properties

Select events whose properties dictionary satisfies given predicate:

log = log.WithEventsSelectedByProperties(props => props.ContainsKey("prop"));

Drop events whose properties dictionary satisfies given predicate:

log = log.WithEventsDroppedByProperties(props => props.ContainsKey("prop"));

Filter by a source context

Select events having a source context with given value:

log = log.WithEventsSelectedBySourceContext("foo");

Drop events having a source context with given value:

log = log.WithEventsDroppedBySourceContext("foo");

Filter by arbitrary event content

Select events satisfying given predicate:

log = log.SelectEvents(@event => @event.Exception == null);

Drop events satisfying given predicate:

log.DropEvents(@event => @event.Exception == null);