Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NLog does not write to a target file with filename containig dots

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?

like image 515
beastofman Avatar asked Apr 17 '13 04:04

beastofman


1 Answers

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.

like image 111
beastofman Avatar answered Oct 27 '22 20:10

beastofman