NLog does not write to the target file with file names with names

When starting a Windows service with the permissions of "NT AUTHORITY \ NETWORK SERVICE", I have a strange problem with NLog: it just doesn’t write anything to the file if the file name contains periods.

I run the Windows service on my WinServer 2008 R2 standard with the .NET Framework 3.5 SP1 enabled, NLog.config looks like this:

<targets> <target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.txt" encoding="utf-8" concurrentWrites="true" keepFileOpen="false" layout="${longdate} ${uppercase:${level}} ${message}"/> </targets> <rules> <logger name="*" minlevel="Trace" writeTo="f" /> </rules> 

After some searching and experimenting with the configuration, I came up with a workaround, not including the file extension in fileName , and it worked fine, which solves the problem, but does not look like a decent solution.

And what makes the problem more like some kind of weird magic for me is that I was able to solve the problem with the log file extension in the configuration of my second Windows service (which runs on the same computer with the same names) by simply changing the information about assembly in design options.

Any ideas?

+6
source share
2 answers

After including the NLog internal log file

 <nlog internalLogFile="c:\temp\nlogproblems.txt" throwExceptions="true" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

I managed to catch a UnathorizedAccessException

 2013-04-17 11:06:14.0445 Error Exception in asynchronous handler NLog.NLogRuntimeException: Exception occurred in NLog ---> System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) 

which led to the conclusion that I should fix the permissions of the logs folder.

Finally, no weirder magic, I just needed to write NETWORK SERVICE to the logs folder.

+13
source

in my case, it was the user running the application pool.

it seems that in some cases you need specific users, in my case IHttpHandler was launched, and I had other mehtods that I called from ProcessRequest, and for some reason it worked fine from ProcessRequest, but from the subtexts I got

 Exception in asynchronous handler NLog.NLogRuntimeException: Exception occurred in NLog ---> System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) 

and after reading 7kun's answer, I gave Everyone complete control, and it worked and then was changed to find the real missing user

0
source

All Articles