NLog does not create a log file

I had this problem turned out that my log file was not being copied to my build directory. The NLog github page had the answer. (I've reformatted the paragraph a little for better readability.) https://github.com/NLog/NLog/wiki/Logging-troubleshooting

NLog cannot find the configuration file. This can happen when the NLog.config file is configured with Build Action = None or Copy to Output Directory = Do not copy in Visual Studio.

Set Build Action = Content and "Copy to Output Directory = Copy if newer to fix this)


from nlog troubleshooting guide

Please check Nlog.config file properties: Copy to output directory should be Copy always

Please view image link https://i.stack.imgur.com/AlUG5.png


The log file was being created - but not in the application directory.

Using ${basedir} layout renderer as part of the file name proved to be a solution.


In case the response marked as answer is not all that clear you can check the example

<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>

Taken from here using AppData location in NLog