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"
By default, the web. nlog file can be found at: C:\Program Files (x86)\Pleasant Solutions\Pleasant Password Server\www\web. nlog.
${basedir} — Directory where the application runs, aka. AppDomain.BaseDirectory.
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}
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.
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