I'm running a workservice as a window service, the log to eventlog is working, but it's not logging to file.
When ran in visual studio, it logs to both eventlog and to file.
What could explain this? Why is the behavior different when ran as a window service? I've also checked to ensure the path is valid and the service user has sufficient permissions to write to the path.
here are my appsettings:
{
"Logging": {
"LogLevel": {
"Default": "Warning"
},
},
"WorkerSetting": {
"Urls": [ "https://google.com" ],
"TimeIntervalMins": 1
},
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "logs/log.log",
"rollingInterval": "Day",
"restrictedToMinimumLevel": "Information"
}
},
{
"Name": "EventLog",
"Args": {
"source": "The Ping Service",
"logName": "Application",
"manageEventSource": true,
"restrictedToMinimumLevel": "Information"
}
}
]
}
}
When ran as a window service, the working directory is the system32 folder, to write to a log file either
Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);