Windows service rights to write in log file
I have created a Windows service using C# that writes logs (with NLog) in C:\ProgramData
.
C:\Windows\System32\
, nothing there).
I suspect that it is an authorization problem so how can I know what rights is my service using?
PS: I have installed my service using the command line C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe C:\PathToMyService\MyService.exe
with Administrator rights.
Run services.msc
, find your service right click and select Properties
. Check the Log On
tab to see which account your service is running under.
As for your problem, by default I think most services run under the Local System Account
which I would assume has permissions to write to the C:\ProgramData
directory. Have you made sure the nlog.config
file is deployed with your service?
You should see your service in the windows control panel fpr services. In the contextmenu you can see the user which runs your service. You can even change the user running your service there.
You have to give that user the right to write in your log directory.
精彩评论