tags:

views:

233

answers:

1
+2  Q: 

AppData For NLog

My NLog targets is like this:

<targets>
  <target xsi:type="Console" name="console" 
    layout="${longdate}|${level}|${message}" />
  <target xsi:type="File" name="ErrorLog" fileName="${basedir}/error.txt"
          layout="${longdate}
          Trace: ${stacktrace} 
          ${message}" />
  <target xsi:type="File" name="AccessLog" fileName="${basedir}/access.txt"
          layout="${shortdate} | ${message}" />
</targets>

But this causes problems if the user isn't an admin on their machine, because they will not have write access to "Program Files". How can I get something like %AppData% to NLog instead of BaseDir?

+2  A: 

you're looking for the nlog special folders.

http://nlog-project.org/lr.specialfolder.html


Example:

...fileName="${specialfolder:folder=ApplicationData}/Program/file.txt"...
Oren Mazor
Yeah, but how do I use it? I've already tried, fileName="${ApplicationData}/RentalEase/access.txt" and it fails silently.
Malfist
I don't remember off the top of my head, but it should look like this:${specialfolder:folder=SPECIALFOLDERNAME}
Oren Mazor
That doesn't work, says it's invalid.
Malfist
${specialfolder:folder=ApplicationData}
Malfist
I missread that, thought you had a '.' between specialfolder and folder instead of a colon
Malfist