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
levelSwitchLoggingLevelSwitchA LoggingLevelSwitch that specifies the level from which the enricher will be applied.
configureEnricherAction<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
configureEnricherisnull
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
enrichFromLevelLogEventLevelThe level from which the enricher will be applied.
configureEnricherAction<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
configureEnricherisnull
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
conditionFunc<LogEvent, bool>A predicate that evaluates to
truewhen the supplied LogEvent should be enriched.configureEnricherAction<LoggerEnrichmentConfiguration>An action that configures the wrapped enricher.
Returns
- LoggerConfiguration
Configuration object allowing method chaining.
Exceptions
- ArgumentNullException
When
conditionisnull- ArgumentNullException
When
configureEnricherisnull
With(params ILogEventEnricher[])
Specifies one or more enrichers that may add properties dynamically to log events.
public LoggerConfiguration With(params ILogEventEnricher[] enrichers)
Parameters
enrichersILogEventEnricher[]Enrichers to apply to all events passing through the logger.
Returns
- LoggerConfiguration
Configuration object allowing method chaining.
Exceptions
- ArgumentNullException
When
enrichersisnull- ArgumentException
When any element of
enrichersisnull
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
namestringThe name of the property to add.
valueobjectThe property value to add.
destructureObjectsboolIf 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
TEnricherEnricher 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
loggerEnrichmentConfigurationLoggerEnrichmentConfigurationThe parent enrichment configuration.
wrapEnricherFunc<ILogEventEnricher, ILogEventEnricher>A function that allows for wrapping ILogEventEnrichers added in
configureWrappedEnricher.configureWrappedEnricherAction<LoggerEnrichmentConfiguration>An action that configures enrichers to be wrapped in
wrapEnricher.
Returns
- LoggerConfiguration
Configuration object allowing method chaining.
Exceptions
- ArgumentNullException
When
loggerEnrichmentConfigurationisnull- ArgumentNullException
When
wrapEnricherisnull- ArgumentNullException
When
configureWrappedEnricherisnull