Table of Contents

Class LoggerEnrichmentConfiguration

Namespace
Serilog.Configuration
Assembly
Serilog.dll

Controls enrichment configuration.

public class LoggerEnrichmentConfiguration
Inheritance
LoggerEnrichmentConfiguration
Inherited Members

Methods

AtLevel(LoggingLevelSwitch, Action<LoggerEnrichmentConfiguration>)

Apply an enricher only to events with a LogEventLevel greater than or equal to the level specified by levelSwitch.

public LoggerConfiguration AtLevel(LoggingLevelSwitch levelSwitch, Action<LoggerEnrichmentConfiguration> configureEnricher)

Parameters

levelSwitch LoggingLevelSwitch

A LoggingLevelSwitch that specifies the level from which the enricher will be applied.

configureEnricher Action<LoggerEnrichmentConfiguration>

An action that configures the wrapped enricher.

Returns

LoggerConfiguration

Configuration object allowing method chaining.

Remarks

This method permits additional information to be attached to e.g. warnings and errors, that might be too expensive to collect or store at lower levels.

Exceptions

ArgumentNullException

When configureEnricher is

null

AtLevel(LogEventLevel, Action<LoggerEnrichmentConfiguration>)

Apply an enricher only to events with a LogEventLevel greater than or equal to enrichFromLevel.

public LoggerConfiguration AtLevel(LogEventLevel enrichFromLevel, Action<LoggerEnrichmentConfiguration> configureEnricher)

Parameters

enrichFromLevel LogEventLevel

The level from which the enricher will be applied.

configureEnricher Action<LoggerEnrichmentConfiguration>

An action that configures the wrapped enricher.

Returns

LoggerConfiguration

Configuration object allowing method chaining.

Remarks

This method permits additional information to be attached to e.g. warnings and errors, that might be too expensive to collect or store at lower levels.

Exceptions

ArgumentNullException

When configureEnricher is

null

FromLogContext()

Enrich log events with properties from LogContext.

public LoggerConfiguration FromLogContext()

Returns

LoggerConfiguration

Configuration object allowing method chaining.

Exceptions

ArgumentNullException

When(Func<LogEvent, bool>, Action<LoggerEnrichmentConfiguration>)

Apply an enricher only when condition evaluates to true.

public LoggerConfiguration When(Func<LogEvent, bool> condition, Action<LoggerEnrichmentConfiguration> configureEnricher)

Parameters

condition Func<LogEvent, bool>

A predicate that evaluates to true when the supplied LogEvent should be enriched.

configureEnricher Action<LoggerEnrichmentConfiguration>

An action that configures the wrapped enricher.

Returns

LoggerConfiguration

Configuration object allowing method chaining.

Exceptions

ArgumentNullException

When condition is

null
ArgumentNullException

When configureEnricher is

null

With(params ILogEventEnricher[])

Specifies one or more enrichers that may add properties dynamically to log events.

public LoggerConfiguration With(params ILogEventEnricher[] enrichers)

Parameters

enrichers ILogEventEnricher[]

Enrichers to apply to all events passing through the logger.

Returns

LoggerConfiguration

Configuration object allowing method chaining.

Exceptions

ArgumentNullException

When enrichers is

null
ArgumentException

When any element of enrichers is

null

WithProperty(string, object?, bool)

Include the specified property value in all events logged to the logger.

public LoggerConfiguration WithProperty(string name, object? value, bool destructureObjects = false)

Parameters

name string

The name of the property to add.

value object

The property value to add.

destructureObjects bool

If true, objects of unknown type will be logged as structures; otherwise they will be converted using ToString().

Returns

LoggerConfiguration

Configuration object allowing method chaining.

With<TEnricher>()

Specifies an enricher that may add properties dynamically to log events.

public LoggerConfiguration With<TEnricher>() where TEnricher : ILogEventEnricher, new()

Returns

LoggerConfiguration

Configuration object allowing method chaining.

Type Parameters

TEnricher

Enricher type to apply to all events passing through the logger.

Wrap(LoggerEnrichmentConfiguration, Func<ILogEventEnricher, ILogEventEnricher>, Action<LoggerEnrichmentConfiguration>)

Helper method for wrapping sinks.

public static LoggerConfiguration Wrap(LoggerEnrichmentConfiguration loggerEnrichmentConfiguration, Func<ILogEventEnricher, ILogEventEnricher> wrapEnricher, Action<LoggerEnrichmentConfiguration> configureWrappedEnricher)

Parameters

loggerEnrichmentConfiguration LoggerEnrichmentConfiguration

The parent enrichment configuration.

wrapEnricher Func<ILogEventEnricher, ILogEventEnricher>

A function that allows for wrapping ILogEventEnrichers added in configureWrappedEnricher.

configureWrappedEnricher Action<LoggerEnrichmentConfiguration>

An action that configures enrichers to be wrapped in wrapEnricher.

Returns

LoggerConfiguration

Configuration object allowing method chaining.

Exceptions

ArgumentNullException

When loggerEnrichmentConfiguration is

null
ArgumentNullException

When wrapEnricher is

null
ArgumentNullException

When configureWrappedEnricher is

null