Windows microservice created from .net core using does not write logs to path
I have created a windows service from c# .net core which uses Serilog.Sinks.Async.File in appsettings.json as below
"Serilog": {
"Using": [
"Serilog.Sinks.Async"
],
"WriteTo": [
{
"Name": "Async",
"Args": {
"configure": [
{
"Name": "File",
"Args": {
"restrictedToMinimumLevel": "Information",
"path": "%PROGRAMDATA%/logs/file.log",
"rollingInterval": "Day",
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
}
}
]
}
},
The above config is just a snippet from appsettings.json but it also includes other standard parameters set in it.
Please let me know if a windows service running as local system can write logs into %PROGRAMDATA% path configured through appsettings.json. The same log file works if it configured as part of the service in Program.cs
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.Destructure.UsingAttributes()
.WriteTo.Async(a =>
a.File(Environment.ExpandEnvironmentVariables("%PROGRAMDATA%\logs\file.log"))
.WriteTo.Console()
.CreateBootstrapLogger()
This logging works.
package
Serilog.AspNetCore
Microsoft.Extensions.Hosting.WindowsServices
Test