How to create a text file in my current directory with NLog?

Try this...

<targets>
    <target name="logfile" xsi:type="File" fileName="${basedir}/file.txt" />
</targets>

Take a look here too, introduction to NLog.


Did you set the NLog.config 'copy to output directory' to 'copy always'?

You should get it to work if you follow their tutorial.


This worked for me ${CurrentDir}

e.g.

<target xsi:type="File" 
    name="ownFile-web" 
    fileName="${CurrentDir}\Logs\nlog-web-${shortdate}.log"
    layout="${longdate}|${event-properties:item=EventId_Id}| [${uppercase:${level}}]${newline}Logger: ${logger}${newline}url: ${aspnet-request-url}${newline}CallSite: ${callsite}${newline}Message: ${message}${onexception:${newline}EXCEPTION:${exception:format=tostring}}${newline}-------${newline}" />

https://github.com/NLog/NLog/wiki/CurrentDir-Layout-Renderer

Tags:

C#

Console

Nlog