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.
Run
services.msc, find your service right click and selectProperties. Check theLog Ontab to see which account your service is running under.As for your problem, by default I think most services run under the
Local System Accountwhich I would assume has permissions to write to theC:\ProgramDatadirectory. Have you made sure thenlog.configfile is deployed with your service?