title: NLog - Conditional File Output
body: <p>I have a C# console app that is using NLog. In that app, I'm trying to log information to file locations conditionally. As a contrived example, let's pretend I need to sometimes log entries to an "evens" log file and sometimes I need to log entries to an "odds" log file. In an attempt to do this, I've setup the following configuration:</p>
  
  <pre><code>&lt;nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
    &lt;targets&gt;
      &lt;target name="evensLogFile" xsi:type="File" fileName="${basedir}/logs/evens.log" createDirs="true" keepFileOpen="true" encoding="utf-8" layout="${longdate} ${message}${exception:format=ToString}"&gt;&lt;/target&gt;
      &lt;target name="oddsLogFile" xsi:type="File" fileName="${basedir}/logs/odds.log" createDirs="true" keepFileOpen="true" encoding="utf-8" layout="${longdate} ${message}${exception:format=ToString}"&gt;&lt;/target&gt;
    &lt;/targets&gt;
  
    &lt;rules&gt;
      &lt;logger name="Evens" minlevel="Trace" writeTo="evensLogFile" /&gt;
      &lt;logger name="Odds" minlevel="Trace" writeTo="oddsLogFile" /&gt;
    &lt;/rules&gt;
  &lt;/nlog&gt;
  </code></pre>
  
  <p>Now, in my code, when I want to write a log entry, I have the following:</p>
  
  <pre><code>public void Log(string message)
  {
    var random = new Random();
    var i = random.Next(1, 11);
  
    Logger logger = null;
    if(i%2 == 0) {
      // somehow get a logger for "evens" 
    } else {
      // somehow get a logger for "odds"
    }
    logger.Log(LogLevel.Info, message);
  }
  </code></pre>
  
  <p>I can successfully write logs to a single log file if I use <code>Logger logger = LogManager.GetCurrentClassLogger();</code> However, I can't figure out how to log different log messages to different files based on some logic. Any help is appreciated!</p>