Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use app data directory in NLog file path

Tags:

logging

nlog

How can I set the target in the NLog.config file to create the log file in the user app data directory?

Below is the desired location of the file.

C:\Users\userid\AppData\Local...\LogFile.txt

I tried setting the fileName in the following ways without any success.

  • target name="logfile" xsi:type="File" fileName="%APPDATA%/.../LogFile.txt"

  • target name="logfile" xsi:type="File" fileName="${APPDATA}/.../LogFile.txt"

  • target name="logfile" xsi:type="File" fileName="${%APPDATA%}/.../LogFile.txt"

like image 901
Somu Avatar asked Nov 20 '13 23:11

Somu


People also ask

Where are NLog logs stored?

By default, the web. nlog file can be found at: C:\Program Files (x86)\Pleasant Solutions\Pleasant Password Server\www\web. nlog.

What is Basedir in NLog?

${basedir} — Directory where the application runs, aka. AppDomain.BaseDirectory.

What can be configured with this NLog config file?

The following types can be configured: Targets - the destinations of a logevent, e.g. file, database, console. Layout - the layout e.g. json, csv, plain-text (default) Layout renderers - the template markers, e.g. ${message}, ${exception}, ${date}


1 Answers

You can achieve that by creating a target like this:

<target name="logfile" xsi:type="File"     fileName="${specialfolder:folder=ApplicationData}/LogFile.txt"/> 

The documentation can be found here.

I hope this helps.

like image 132
Jacco Dieleman Avatar answered Oct 22 '22 00:10

Jacco Dieleman