Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Event Log Source when logging in dotNet Core

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.

like image 222
David Croft Avatar asked Sep 06 '25 10:09

David Croft


1 Answers

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";
            });

            // ...
        });
like image 51
C. Augusto Proiete Avatar answered Sep 09 '25 02:09

C. Augusto Proiete