title: How to setup event log for .NET Core 3.0 Worker Service
body: <p>I'm working with the new Worker Service app template with .NET Core 3.0 Preview and am trying to add event logging using the <code>AddEventLog</code> method. However, I cannot see any of my logs via the Event Viewer in Windows.</p>
  
  <p>I have a very simple Worker app setup and have configured logging in the <code>Program.cs</code> file as follows:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
  Host.CreateDefaultBuilder(args)
      .UseWindowsService()
      .ConfigureLogging((context, logging) =&gt;
      {
          logging.AddEventLog(new EventLogSettings()
          {
              SourceName = "MyTestSource",
              LogName = "MyTestLog"
          });
      })
      .ConfigureServices((hostContext, services) =&gt;
      {
          services.AddHostedService&lt;Worker&gt;();
      });
  </code></pre>
  
  <p>I then have some logging statements in the <code>Worker.cs</code> file as follows:</p>
  
  <pre class="lang-cs prettyprint-override"><code>private readonly ILogger&lt;Worker&gt; _logger;
  
  public Worker(ILogger&lt;Worker&gt; logger)
  {
      _logger = logger;
  }
  
  public override async Task StartAsync(CancellationToken cancellationToken)
  {
      _logger.LogInformation($"Worker started at: {DateTime.Now}");
      await base.StartAsync(cancellationToken);
  }
  
  public override async Task StopAsync(CancellationToken cancellationToken)
  {
      _logger.LogInformation($"Worker stopped at: {DateTime.Now}");
      await base.StopAsync(cancellationToken);
  }
  
  protected override async Task ExecuteAsync(CancellationToken stoppingToken)
  {
      while (!stoppingToken.IsCancellationRequested)
      {
          _logger.LogInformation( $"Worker running at: {DateTime.Now}");
          await Task.Delay(1000, stoppingToken);
      }
  }
  </code></pre>
  
  <p>To setup the event logs, I ran the following from an elevated Powershell prompt:</p>
  
  <p><code>New-EventLog -LogName MyTestLog -Source MyTestSource</code></p>
  
  <p>If I open the Event Viewer I can see "MyTestLog" listed below "Applications and Services Logs".</p>
  
  <p>Then, to set up my Worker as a Windows service, I ran the following commands from an elevated command prompt:</p>
  
  <p><code>dotnet publish -o publish</code> (Publishes project and outputs to publish directory)</p>
  
  <p><code>sc create MyTestService binPath=&lt;path to exe in publish directory&gt;</code></p>
  
  <p>The service is created successfully, and I can see it in the Services viewer application. From there, I manually start the service and then check back in the Event Viewer and no logs are displayed.</p>
  
  <p>I was expecting there to be some logs. However, the "MyTestLog" section remains empty in the Event Viewer.</p>