Table of Contents

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

condition Func<LogEvent, bool>

A predicate that evaluates to true when the supplied LogEvent should be written to the configured sink.

configureSink Action<LoggerSinkConfiguration>

An action that configures the wrapped sink.

Returns

LoggerConfiguration

Configuration object allowing method chaining.

Exceptions

ArgumentNullException

When condition is

null
ArgumentNullException

When configureSink is

null

CreateSink(Action<LoggerSinkConfiguration>)

Helper method for constructing sinks outside of a logger pipeline.

public static ILogEventSink CreateSink(Action<LoggerSinkConfiguration> configure)

Parameters

configure Action<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 configure is

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

logger ILogger

The sub-logger.

attemptDispose bool

Whether to shut down automatically the sub-logger when the parent logger is disposed.

restrictedToMinimumLevel LogEventLevel

The minimum level for events passed through the sink.

levelSwitch LoggingLevelSwitch

A 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 logger is

null

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

configureLogger Action<LoggerConfiguration>

An action that configures the sub-logger.

restrictedToMinimumLevel LogEventLevel

The minimum level for events passed through the sink. Ignored when levelSwitch is specified.

levelSwitch LoggingLevelSwitch

A 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 configureLogger is

null

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

batchedLogEventSink IBatchedLogEventSink

The batched sink to receive events.

batchingOptions BatchingOptions

Options that control batch sizes, buffering time, and backpressure.

restrictedToMinimumLevel LogEventLevel

The minimum level for events passed through the sink. Ignored when levelSwitch is specified.

levelSwitch LoggingLevelSwitch

A 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

logEventSink ILogEventSink

The sink.

restrictedToMinimumLevel LogEventLevel

The minimum level for events passed through the sink. Ignored when levelSwitch is specified.

levelSwitch LoggingLevelSwitch

A 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

batchingOptions BatchingOptions
restrictedToMinimumLevel LogEventLevel
levelSwitch LoggingLevelSwitch

Returns

LoggerConfiguration

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

restrictedToMinimumLevel LogEventLevel

The minimum level for events passed through the sink. Ignored when levelSwitch is specified.

levelSwitch LoggingLevelSwitch

A switch allowing the pass-through minimum level to be changed at runtime.

Returns

LoggerConfiguration

Configuration object allowing method chaining.

Type Parameters

TSink

The 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

loggerSinkConfiguration LoggerSinkConfiguration

The parent sink configuration.

wrapSink Func<ILogEventSink, ILogEventSink>

A function that allows for wrapping ILogEventSinks added in configureWrappedSink.

configureWrappedSink Action<LoggerSinkConfiguration>

An action that configures sinks to be wrapped in wrapSink.

restrictedToMinimumLevel LogEventLevel

The minimum level for events passed through the sink. Ignored when levelSwitch is specified.

levelSwitch LoggingLevelSwitch

A 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 loggerSinkConfiguration is

null
ArgumentNullException

When wrapSink is

null
ArgumentNullException

When configureWrappedSink is

null

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

wrapSink Func<ILogEventSink, ILogEventSink>

A function that allows for wrapping ILogEventSinks added in configureWrappedSink.

configureWrappedSink Action<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 wrapSink is

null
ArgumentNullException

When configureWrappedSink is

null