SidD
SidD

Reputation: 6347

Serilog logging to file in worker service .net core 3.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?

Upvotes: 1

Views: 3150

Answers (1)

Farhad Zamani
Farhad Zamani

Reputation: 5861

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.

Upvotes: 2

Related Questions