Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NLog ProgramData path

Tags:

path

logging

nlog

When a NLog.config has an absolute path, all is working nice:

 <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  autoReload="true"
  internalLogLevel="Info"
  internalLogFile="F:\ProgramData\MyApp\myfolder\nlog.txt">

if I try to use a specialfolder variable, it fails to work:

internalLogFile="${specialfolder:folder=CommonApplicationData}\MyApp\myfolder\nlog.txt">

What NLog.config path should I use to make NLog use the ProgramData folder without using an absolute path?

I use NLog v. 2.0 on Windows 7

like image 595
rem Avatar asked Oct 10 '22 07:10

rem


2 Answers

You can't use layout renderers ${...} in the internalLogFile property. They are for target's layout only:

<target layout="${...}" />

Try to use relative path like "..\myfolder\nlog.txt"

like image 133
kolbasov Avatar answered Oct 11 '22 20:10

kolbasov


Based on NLog Special folders:

fileName="${specialfolder:folder=ApplicationData}/Program/file.txt"

May do the trick

like image 31
DanielV Avatar answered Oct 11 '22 22:10

DanielV