Skip to content

Commit

Permalink
fix: Update Serilog EventLog sink configuration to enable event sourc…
Browse files Browse the repository at this point in the history
…e creation (if the app is running with admin privileges). (#1963)
  • Loading branch information
tippmar-nr authored Oct 10, 2023
1 parent c0e06e9 commit 274072b
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/Agent/NewRelic/Agent/Core/Logging/LoggerBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,26 @@ private static LoggerConfiguration ConfigureEventLogSink(this LoggerConfiguratio
#if NETFRAMEWORK
const string eventLogName = "Application";
const string eventLogSourceName = "New Relic .NET Agent";

loggerConfiguration
.WriteTo.Logger(configuration =>
{
configuration
.ExcludeAuditLog()
.WriteTo.EventLog(
source: eventLogSourceName,
logName: eventLogName,
restrictedToMinimumLevel: LogEventLevel.Warning,
outputTemplate: "{Level}: {Message}{NewLine}{Exception}"
);
});
try
{
loggerConfiguration
.WriteTo.Logger(configuration =>
{
configuration
.ExcludeAuditLog()
.WriteTo.EventLog(
source: eventLogSourceName,
logName: eventLogName,
restrictedToMinimumLevel: LogEventLevel.Warning,
outputTemplate: "{Level}: {Message}{NewLine}{Exception}",
manageEventSource: true // Serilog will create the event source if it doesn't exist *and* if the app is running with admin privileges
);
});
}
catch
{
// ignored -- there's nothing we can do at this point, as EventLog is our "fallback" logger and if it fails, we're out of luck
}
#endif
return loggerConfiguration;
}
Expand Down

0 comments on commit 274072b

Please sign in to comment.