问题
I have created a Windows service using C# that writes logs (with NLog) in C:\ProgramData
.
When I debug the service (on my Windows 7) (using the code written above), the log file is correctly created and log records correctly written.
But when I install the service on my server which runs on Windows server 2008 (x86), no log file is created (I have also checked in 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.
回答1:
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?
回答2:
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.
来源:https://stackoverflow.com/questions/7525854/windows-service-rights-to-write-in-log-file