Class LoggerSinkConfiguration
- Namespace
- Serilog.Configuration
- Assembly
- Serilog.dll
Controls sink configuration.
public class LoggerSinkConfiguration
- Inheritance
-
LoggerSinkConfiguration
- Inherited Members
Methods
Conditional(Func<LogEvent, bool>, Action<LoggerSinkConfiguration>)
Write to a sink only when condition evaluates to true.
public LoggerConfiguration Conditional(Func<LogEvent, bool> condition, Action<LoggerSinkConfiguration> configureSink)
Parameters
conditionFunc<LogEvent, bool>A predicate that evaluates to
truewhen the supplied LogEvent should be written to the configured sink.configureSinkAction<LoggerSinkConfiguration>An action that configures the wrapped sink.
Returns
- LoggerConfiguration
Configuration object allowing method chaining.
Exceptions
- ArgumentNullException
When
conditionisnull- ArgumentNullException
When
configureSinkisnull
CreateSink(Action<LoggerSinkConfiguration>)
Helper method for constructing sinks outside of a logger pipeline.
public static ILogEventSink CreateSink(Action<LoggerSinkConfiguration> configure)
Parameters
configureAction<LoggerSinkConfiguration>An action that configures one or more sinks.
Returns
- ILogEventSink
If only a single sink is configured, it will be returned from CreateSink(Action<LoggerSinkConfiguration>). If zero or many sinks are configured, they will be combined in an aggregating wrapper.
Exceptions
- ArgumentNullException
When
configureis
.null
Logger(ILogger, bool, LogEventLevel, LoggingLevelSwitch?)
Write log events to a sub-logger, where further processing may occur. Events through the sub-logger will be constrained by filters and enriched by enrichers that are active in the parent. A sub-logger cannot be used to log at a more verbose level, but a less verbose level is possible.
public LoggerConfiguration Logger(ILogger logger, bool attemptDispose = false, LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose, LoggingLevelSwitch? levelSwitch = null)
Parameters
loggerILoggerThe sub-logger.
attemptDisposeboolWhether to shut down automatically the sub-logger when the parent logger is disposed.
restrictedToMinimumLevelLogEventLevelThe minimum level for events passed through the sink.
levelSwitchLoggingLevelSwitchA switch allowing the pass-through minimum level to be changed at runtime. Can be
null
Returns
- LoggerConfiguration
Configuration object allowing method chaining.
Exceptions
- ArgumentNullException
When
loggerisnull
Logger(Action<LoggerConfiguration>, LogEventLevel, LoggingLevelSwitch?)
Write log events to a sub-logger, where further processing may occur. Events through the sub-logger will be constrained by filters and enriched by enrichers that are active in the parent. A sub-logger cannot be used to log at a more verbose level, but a less verbose level is possible.
public LoggerConfiguration Logger(Action<LoggerConfiguration> configureLogger, LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose, LoggingLevelSwitch? levelSwitch = null)
Parameters
configureLoggerAction<LoggerConfiguration>An action that configures the sub-logger.
restrictedToMinimumLevelLogEventLevelThe minimum level for events passed through the sink. Ignored when
levelSwitchis specified.levelSwitchLoggingLevelSwitchA switch allowing the pass-through minimum level to be changed at runtime. Can be
null
Returns
- LoggerConfiguration
Configuration object allowing method chaining.
Exceptions
- ArgumentNullException
When
configureLoggerisnull
Sink(IBatchedLogEventSink, BatchingOptions, LogEventLevel, LoggingLevelSwitch?)
Write log events to an IBatchedLogEventSink. Events will be internally buffered, and written to the sink in batches.
public LoggerConfiguration Sink(IBatchedLogEventSink batchedLogEventSink, BatchingOptions batchingOptions, LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose, LoggingLevelSwitch? levelSwitch = null)
Parameters
batchedLogEventSinkIBatchedLogEventSinkThe batched sink to receive events.
batchingOptionsBatchingOptionsOptions that control batch sizes, buffering time, and backpressure.
restrictedToMinimumLevelLogEventLevelThe minimum level for events passed through the sink. Ignored when
levelSwitchis specified.levelSwitchLoggingLevelSwitchA switch allowing the pass-through minimum level to be changed at runtime.
Returns
- LoggerConfiguration
Configuration object allowing method chaining.
Sink(ILogEventSink, LogEventLevel, LoggingLevelSwitch?)
Write log events to an ILogEventSink.
public LoggerConfiguration Sink(ILogEventSink logEventSink, LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose, LoggingLevelSwitch? levelSwitch = null)
Parameters
logEventSinkILogEventSinkThe sink.
restrictedToMinimumLevelLogEventLevelThe minimum level for events passed through the sink. Ignored when
levelSwitchis specified.levelSwitchLoggingLevelSwitchA switch allowing the pass-through minimum level to be changed at runtime.
Returns
- LoggerConfiguration
Configuration object allowing method chaining.
Sink<TSink>(BatchingOptions, LogEventLevel, LoggingLevelSwitch?)
public LoggerConfiguration Sink<TSink>(BatchingOptions batchingOptions, LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose, LoggingLevelSwitch? levelSwitch = null) where TSink : IBatchedLogEventSink, new()
Parameters
batchingOptionsBatchingOptionsrestrictedToMinimumLevelLogEventLevellevelSwitchLoggingLevelSwitch
Returns
Type Parameters
TSink
Sink<TSink>(LogEventLevel, LoggingLevelSwitch?)
Write log events to the specified ILogEventSink.
public LoggerConfiguration Sink<TSink>(LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose, LoggingLevelSwitch? levelSwitch = null) where TSink : ILogEventSink, new()
Parameters
restrictedToMinimumLevelLogEventLevelThe minimum level for events passed through the sink. Ignored when
levelSwitchis specified.levelSwitchLoggingLevelSwitchA switch allowing the pass-through minimum level to be changed at runtime.
Returns
- LoggerConfiguration
Configuration object allowing method chaining.
Type Parameters
TSinkThe sink.
Wrap(LoggerSinkConfiguration, Func<ILogEventSink, ILogEventSink>, Action<LoggerSinkConfiguration>, LogEventLevel, LoggingLevelSwitch?)
Helper method for constructing wrapper sinks.
[Obsolete("Use the two-argument `Wrap()` overload to construct a wrapper, then use `WriteTo.Sink()` to add it to the configuration.")]
public static LoggerConfiguration Wrap(LoggerSinkConfiguration loggerSinkConfiguration, Func<ILogEventSink, ILogEventSink> wrapSink, Action<LoggerSinkConfiguration> configureWrappedSink, LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose, LoggingLevelSwitch? levelSwitch = null)
Parameters
loggerSinkConfigurationLoggerSinkConfigurationThe parent sink configuration.
wrapSinkFunc<ILogEventSink, ILogEventSink>A function that allows for wrapping ILogEventSinks added in
configureWrappedSink.configureWrappedSinkAction<LoggerSinkConfiguration>An action that configures sinks to be wrapped in
wrapSink.restrictedToMinimumLevelLogEventLevelThe minimum level for events passed through the sink. Ignored when
levelSwitchis specified.levelSwitchLoggingLevelSwitchA switch allowing the pass-through minimum level to be changed at runtime. Can be
null
Returns
- LoggerConfiguration
Configuration object allowing method chaining.
Exceptions
- ArgumentNullException
When
loggerSinkConfigurationisnull- ArgumentNullException
When
wrapSinkisnull- ArgumentNullException
When
configureWrappedSinkisnull
Wrap(Func<ILogEventSink, ILogEventSink>, Action<LoggerSinkConfiguration>)
Helper method for constructing wrapper sinks. This may be preferred over CreateSink(Action<LoggerSinkConfiguration>) because it handles delegation of Dispose() through to the wrapped sink in cases where the wrapper is not disposable.
public static ILogEventSink Wrap(Func<ILogEventSink, ILogEventSink> wrapSink, Action<LoggerSinkConfiguration> configureWrappedSink)
Parameters
wrapSinkFunc<ILogEventSink, ILogEventSink>A function that allows for wrapping ILogEventSinks added in
configureWrappedSink.configureWrappedSinkAction<LoggerSinkConfiguration>An action that configures sinks to be wrapped in
wrapSink.
Returns
- ILogEventSink
The wrapper, or a sink that will handle invoking the wrapper.
Exceptions
- ArgumentNullException
When
wrapSinkisnull- ArgumentNullException
When
configureWrappedSinkisnull