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?
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.