When starting my windows service with "NT AUTHORITY\NETWORK SERVICE" credentials I experience a strange issue with NLog: it simply does not log anything to the file target if the filename contains dots.
I'm running windows service on my WinServer 2008 R2 Standard with .NET Framework 3.5 SP1 feature enabled, NLog.config is as follows:
<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 googling and experimenting with config I came up with a workaround by not including file extension in fileName
parameter and it worked just fine, which solves the problem but does not look like a decent solution.
And what makes the issue look more like a some weird magic to me is the fact that I managed to solve the problem with log file extension in config of my second windows service (which is running on the same machine with the same credenials) simply by changing assembly information in project options.
Any ideas?
After enabling NLog's 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 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 a conclusion that I should fix the logs
folder permissions.
Finally no more weird magic, I just had to allow NETWORK SERVICE
writing into the logs
folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With