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
LoggingLevelSwitchA 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
isnull
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
LogEventLevelThe 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
isnull
FromLogContext()
Enrich log events with properties from LogContext.
public LoggerConfiguration FromLogContext()
Returns
- LoggerConfiguration
Configuration object allowing method chaining.
Exceptions
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
isnull
- ArgumentNullException
When
configureEnricher
isnull
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
isnull
- ArgumentException
When any element of
enrichers
isnull
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
stringThe name of the property to add.
value
objectThe property value to add.
destructureObjects
boolIf 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
LoggerEnrichmentConfigurationThe 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
isnull
- ArgumentNullException
When
wrapEnricher
isnull
- ArgumentNullException
When
configureWrappedEnricher
isnull