Windows service rights to write in log file

点点圈 提交于 2021-02-10 07:11:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!