开发者

Windows service rights to write in log file

开发者 https://www.devze.com 2023-04-08 09:24 出处:网络
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

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 fil开发者_如何学Goe 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号