title: Update NLog target filename at runtime
body: <p>In my application, I work on several thousand of document a day. I'd like, in some cases some logs, one log by document. Then I'd like for a specific target change the output filename (and only the filename) at runtime.</p>
  
  <p>Around the web I found how to create a target by programming me I'd like just update a the filename by programming. I tried the code below. The error I receive is "LayoutRender cannot be found 'logDirectory'.</p>
  
  <p>Any idea ?</p>
  
  <p>Thanks,</p>
  
  <pre><code>var target = (FileTarget)LogManager.Configuration.FindTargetByName("logfile");
  target.FileName = "${logDirectory}/file2.txt";
  
  LoggingConfiguration config = new LoggingConfiguration();
  var asyncFileTarget = new AsyncTargetWrapper(target);
  config.AddTarget("logfile", asyncFileTarget);
  
  LogManager.Configuration = config;
  </code></pre>
  
  <p>The config file is :</p>
  
  <pre><code>  &lt;nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;variable name="logDirectory" value="C:/MyLogs"/&gt;
      &lt;targets&gt;
        &lt;target name="logfile" xsi:type="File" layout="${date:format=dd/MM/yyyy HH\:mm\:ss.fff}|${level}|${stacktrace}|${message}" fileName="${logDirectory}/file.txt" /&gt;
      &lt;/targets&gt;
  
      &lt;rules&gt;
        &lt;logger name="*" minlevel="Info" writeTo="logfile" /&gt;
      &lt;/rules&gt;    
    &lt;/nlog&gt;
  </code></pre>