How do I specify the windows event log source when using the dotNet core logging framework?
I'm able to log to the Windows EventLog but it is unclear how I specify the Source for the log entry.
As of .NET 3.x, an EventLog
is automatically added to the configuration when running on Windows, thus instead of adding another Event Log, you should just configure the EventLogSettings
for the existing EventLog
, in order to set your Source name.
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.Configure<EventLogSettings>(settings =>
{
settings.SourceName = "NameOfYourEventSource";
});
// ...
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With