Reputation: 105
I have a windows service (.net 6), I am using Serilog.Extensions.Logging.File to add logging file, when I run exe file it creates a file and works fine, but when I install it as windows service it is not working. In Event log all looks good, if there is any error for service I can see it in event viewer log. (locally and in the server I have the same condition)
I am running under LOCAL SERVICE if that helps. It has Full access. I have created the logs directory under my application folder.
appsetting.json file content:
"Logging": {
"File": {
"PathFormat": "Logs/log-{Date}.txt",
"fileSizeLimitBytes": 10485760,
"retainedFileCountLimit": 10
}
I checked the similar questions like this: Similar question not helpful for me
Upvotes: 1
Views: 1802
Reputation: 105
There was an issue in server which it was showing current working directory set to application folder but in fact it was saving in the windows folder, after restarting windows, it is solved.
Upvotes: 1
Reputation: 2861
A windows service, when registered and started, is not running from the folder from which you originally registered the service. Instead, an instance of the service is held and the execution context is under the OS folder where services are held once registered.
Think of it as the "hosting directory" that you know from web-driven services proobably.
You can look up the directory of a service from the cmd with the command below:
sc qc <service name>
Upvotes: 0