Изменение переменных NLog (C#)

Всех приветствую. Хотелось бы узнать, как осуществить проверку значения переменной deviceId в файле NLog.config. Сейчас, переменная deviceId в коде С# и переменная deviceId в файле NLog.config - это две разные сущности, но они должны быть одной и той же переменной.

Код С#:

        static void Main(string[] args)
    {
        Logger log = LogManager.GetCurrentClassLogger();

        // log only Message 2
        //int res;
        //res = Sum(2, 5);
        //log.Debug($"{res}");

        int deviceId;
        deviceId = 1;
        //log.Debug("Message " + $"{deviceId}");
        log.Debug("");
        deviceId = 2;
        //log.Debug("Message " + $"{deviceId}");
        log.Debug("");
        deviceId = 3;
        //log.Debug("Message " + $"{deviceId}");
        log.Debug("");
    }

Код в NLog.config:

    <?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
      autoReload="true"
      throwExceptions="false"
      internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">

  <variable name="myvar" value="myvalue"/>
  <variable name="deviceId" value="2" />
  
  <targets>
    <target xsi:type="File" name="file" fileName="${basedir}/logs/${shortdate}.log"
    layout="${when:when=${deviceId} == 2:*}"/>
  </targets>

    <rules>
        <logger name="*" minlevel="Trace" writeTo="file" />
    </rules>
</nlog>

Ответы (0 шт):