title: NLog filename per thread
body: <p>I'm trying to create log filename dynamically using NLog (.NET Framework 4.8). Basically, I would like unique filename created every time new thread is fired. I got it somewhat working with the following sections:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;target xsi:type="File" name="ownFile" header="${machinename}${newline}${threadid}${newline}"
              fileName="${mdc:logFolder}\${date:format=yyyyMMdd}\log_${activityid}.txt" layout="${date}|${activityid}|${level:uppercase=true}|${message} ${exception}|${logger}|${all-event-properties}"
              footer="${newline}Finished at: ${date}"/&gt;
  
  &lt;logger name="*" minlevel="Debug" writeTo="ownFile" /&gt;
  </code></pre>
  
  <p>When thread is started, it sets the logFolder using <code>MappedDiagnosticsContext.Set</code> and sets the <code>Trace.CorrelationManager.ActivityId</code>. But there is one problem. The footer part is only written when FileTarget is disposed, which I believe then closes all file appenders cached inside FileTarget. </p>
  
  <p>Is there a way for me to manually close the internal file appender for dynamic file? What I want is when thread is done with its processing is to close the dynamic log file.</p>
  
  <p>I also have another approach working where I add new FileTarget when thread starts and the remove it when thread is finished. It does work, but I would prefer config file solution.</p>
  
  <p>Thanks in advance.</p>