1

I am new to worker service.I have created worker service in .net core 3.1. Referred this tutorial File logging in .Net 5 worker service using serilog. It is working as expected, i.e it is logging to the file. Now i installed the service i had have to use

Microsoft.Extensions.Hosting.WindowsServices

and modify the code as below.

public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args).ConfigureLogging(logging =>
        {
            logging.AddSerilog();
        })
       .ConfigureServices((hostContext, services) =>
        {
            services.AddHostedService<Worker>();
        }).UseWindowsService(); // This is the change i required to install as service

Now when i am running the service, it is not logging to the file. Am i missing something?

SidD
  • 5,697
  • 4
  • 18
  • 30

1 Answers1

2

WindowsService are run in System32 folder. for example: C:\Windows\System32

You should check this folder for your logs.

Or you should add full path address to logs path.

Farhad Zamani
  • 5,381
  • 2
  • 16
  • 41
  • This is genius! Has had me stumped for a while now. Is there a way to have it in the path that the service is in? So in debug, command prompt this works as expected? – TheNerdyNerd Jun 06 '22 at 19:42