src/Serilog.Sinks.EventLog/LoggerConfigurationEventLogExtensions.cs
/// <summary>
/// Adds a sink that writes log events to the Windows event log.
/// </summary>
/// <param name="loggerConfiguration">The logger configuration.</param>
/// <param name="source">The source name by which the application is registered on the local computer. </param>
/// <param name="logName">The name of the log the source's entries are written to. Possible values include Application, System, or a custom event log. </param>
/// <param name="machineName">The name of the machine hosting the event log written to.  The local machine by default.</param>
/// <param name="manageEventSource">If true, check/create event source as required.  Defaults to false i.e. do not allow sink to manage event source creation.</param>
/// <param name="outputTemplate">A message template describing the format used to write to the sink.  The default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".</param>
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
/// <param name="eventIdProvider">Supplies event ids for emitted log events.</param>
/// <returns>Logger configuration, allowing configuration to continue.</returns>
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
Adds a sink that writes log events to the Windows event log.
Adds a sink that writes log events to the Windows event log .
public static LoggerConfiguration EventLog(
            this LoggerSinkConfiguration loggerConfiguration,
            string source,
            string logName = null,
            string machineName = ".",
            bool manageEventSource = false,
            string outputTemplate = DefaultOutputTemplate,
            IFormatProvider formatProvider = null,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            IEventIdProvider eventIdProvider = null)
        {
            if (loggerConfiguration == null)
            {
                throw new ArgumentNullException(nameof(loggerConfiguration));
            }
#if NETSTANDARD2_0
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                throw new PlatformNotSupportedException(RuntimeInformation.OSDescription);
            }
#endif
            var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
            if (eventIdProvider == null)
            {
                return loggerConfiguration.Sink(new EventLogSink(source, logName, formatter, machineName, manageEventSource), restrictedToMinimumLevel);
            }
            return loggerConfiguration.Sink(new EventLogSink(source, logName, formatter, machineName, manageEventSource, eventIdProvider), restrictedToMinimumLevel);
        }
public static LoggerConfiguration EventLog ( this LoggerSinkConfiguration loggerConfiguration , string source , string logName = null , string machineName = " " , bool manageEventSource = false , string outputTemplate = DefaultOutputTemplate , IFormatProvider formatProvider = null , LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum , IEventIdProvider eventIdProvider = null ) { if ( loggerConfiguration == null ) { throw new ArgumentNullException ( nameof ( loggerConfiguration ) ) ; } if NETSTANDARD2_0 if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ) { throw new PlatformNotSupportedException ( RuntimeInformation . OSDescription ) ; } endif var formatter = new MessageTemplateTextFormatter ( outputTemplate , formatProvider ) ; if ( eventIdProvider == null ) { return loggerConfiguration . Sink ( new EventLogSink ( source , logName , formatter , machineName , manageEventSource ) , restrictedToMinimumLevel ) ; } return loggerConfiguration . Sink ( new EventLogSink ( source , logName , formatter , machineName , manageEventSource , eventIdProvider ) , restrictedToMinimumLevel ) ; }
Adds a sink that writes log events to the Windows event log.
Adds a sink that writes log events to the Windows event log .
// Verify the code is running on Windows.
Logger configuration, allowing configuration to continue.
Logger configuration allowing configuration to continue .
A required parameter is null.
A required parameter is null .
LoggerSinkConfiguration
this
source
string
The source name by which the application is registered on the local computer.
The source name by which the application is registered on the local computer .
logName
string
The name of the log the source's entries are written to. Possible values include Application, System, or a custom event log.
The name of the log the source ' s entries are written to . Possible values include Application System or a custom event log .
machineName
string
The name of the machine hosting the event log written to.  The local machine by default.
The name of the machine hosting the event log written to . The local machine by default .
manageEventSource
bool
If true, check/create event source as required.  Defaults to false i.e. do not allow sink to manage event source creation.
If true check / create event source as required . Defaults to false i . e . do not allow sink to manage event source creation .
outputTemplate
string
A message template describing the format used to write to the sink.  The default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".
A message template describing the format used to write to the sink . The default is " { Timestamp } [ { Level } ] { Message } { NewLine } { Exception } " .
formatProvider
IFormatProvider
Supplies culture-specific formatting information, or null.
Supplies culture - specific formatting information or null .
restrictedToMinimumLevel
LogEventLevel
The minimum log event level required in order to write an event to the sink.
The minimum log event level required in order to write an event to the sink .
eventIdProvider
IEventIdProvider
Supplies event ids for emitted log events.
Supplies event ids for emitted log events .
loggerConfiguration
The logger configuration.
The logger configuration .