Serilog in Windows-Service not writing to logfile

 loggerFactory.AddFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log-{Date}.txt"));

Try this one, it worked in my ASP.NET core 2 application runs as windows service


It's most likely that the account under which the services is running lacks permission to write to the log file location. Try changing the log file location to the system's temp folder to see if this is the case.

If this still fails, using Serilog's SelfLog to get exception information is your best bet.


We had the same issue, this is what we found:

  • Serilog configured for rolling logfiles and writing to Seq
  • Ddrable logs was enabled.

Symptoms - No log files were being created - No logs written to Seq.

As per @gdoten's comment, our log files were being written to \windows\syswow64 (service was running as localservice).
We believe the permissions on these files may not of allowed the durable spool file to be read causing no logs to be written to Seq.

Fix was to hard code the path of the rollinglogfile and buffer.


I had a very similar issue. In my case, the problem was with relative paths. I just had to specify the absolute path. Now it works like a charm.

WriteTo.RollingFile(AppDomain.CurrentDomain.BaseDirectory + "\\logs\\log-{Date}.log")