serilog-sinks-eventlog
serilog-sinks-eventlog copied to clipboard
EventLogSink is not thread safe
I just discovered that creation of new event log and sources is not thread safe. It is failing during our tests as they are executed in parallel.
if (System.Diagnostics.EventLog.SourceExists(source, log.MachineName))
{
var existingLogWithSourceName = System.Diagnostics.EventLog.LogNameFromSourceName(source, log.MachineName);
if (!string.IsNullOrWhiteSpace(existingLogWithSourceName) &&
!log.Log.Equals(existingLogWithSourceName, StringComparison.OrdinalIgnoreCase))
{
// Remove the source from the previous log so we can associate it with the current log name
System.Diagnostics.EventLog.DeleteEventSource(source, log.MachineName);
oldLogName = existingLogWithSourceName;
}
}
else
{
System.Diagnostics.EventLog.CreateEventSource(sourceData);
}
https://github.com/serilog/serilog-sinks-eventlog/blob/dev/src/Serilog.Sinks.EventLog/Sinks/EventLog/EventLogSink.cs#L97