serilog-sinks-eventlog
serilog-sinks-eventlog copied to clipboard
Serilog adding EventLog as Sink
We are usingSerilog and we are adding EventLog as Sink from configuration. This is how our code looks.
public static ILoggingBuilder AddSerilog(this ILoggingBuilder logging, IConfiguration configuration)
{
if (logging == null)
{
throw new ArgumentNullException(nameof(logging));
}
var log = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
// .WriteTo.EventLog("Exception Definition", manageEventSource: true)
.CreateLogger();
logging.AddSerilog(log, dispose: true);
return logging;
}
And this our config file.
<add key="Serilog:Using:0" value="Serilog.Sinks.EventLog" />
<add key="Serilog:MinimumLevel" value="Verbose" />
For some reason the log doesnt get set with the EventLog sink. However If I change the config file Serilog:using:0 key value to Serilog.Sinks.Console or Serilog.Sinks.RollingFile the log gets created properly.
Also If I change code to directly invoke WriteTo.EventLog It works. Can someone please tell what I am doing wrong.
<add key="serilog:using:Console" value="Serilog.Sinks.Console"/>
<add key="serilog:using:EventLog" value="Serilog.Sinks.EventLog"/>
<add key="serilog:minimum-level" value="Debug"/>
<add key="serilog:minimum-level:override:Microsoft" value="Warning"/>
<add key="serilog:write-to:Console"/>
<add key="serilog:write-to:EventLog.source" value="MySource"/>
<add key="serilog:write-to:EventLog.logName" value="MyName"/>
<add key="serilog:write-to:EventLog.manageEventSource" value="true"/>
The above works for me.