Redirecting log to json file using NLog

340 Views Asked by At

In my organization we use UIPath and Robots logging is based on NLog. The default nlog configuration looks like:

<?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">
  <variable name="WorkflowLoggingDirectory" value="${specialfolder:folder=LocalApplicationData}/UiPath/Logs" />
  <rules>
    <logger name="WorkflowLogging" writeTo="WorkflowLogFiles" final="true" />
    <logger minLevel="Info" writeTo="EventLog" />
  </rules>
  <targets>
    <target type="File" name="WorkflowLogFiles" 
            fileName="${WorkflowLoggingDirectory}/${shortdate}_Execution.log" 
            layout="${time} ${level} ${message}" 
            keepFileOpen="true" 
            openFileCacheTimeout="5" 
            concurrentWrites="true" 
            encoding="utf-8" 
            writeBom="true" />
    <target type="EventLog" name="EventLog" 
            layout="${processname} ${assembly-version} ${newline}${message}" 
            source="UiPath" log="Application" />
  </targets>
</nlog>

It works but we decided to redirect logs also to json file. Now NLog.config file looks like:

<?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">
  <variable name="WorkflowLoggingDirectory" value="${specialfolder:folder=LocalApplicationData}/UiPath/Logs" />
  <rules>
    <logger name="WorkflowLogging" writeTo="WorkflowLogFiles" final="true" />
    <logger name="ToJson" writeTo="jsonFile" />
    <logger minLevel="Info" writeTo="EventLog" />
  </rules>
  <targets>
    <target type="File" name="WorkflowLogFiles" 
            fileName="${WorkflowLoggingDirectory}/${shortdate}_Execution.log" 
            layout="${time} ${level} ${message}" 
            keepFileOpen="true" 
            openFileCacheTimeout="5" 
            concurrentWrites="true" 
            encoding="utf-8" 
            writeBom="true" />
    <target type="EventLog" name="EventLog" 
            layout="${processname} ${assembly-version} ${newline}${message}" 
            source="UiPath" log="Application" />
    <target type="File" name="jsonFile"
            fileName="${WorkflowLoggingDirectory}/log.json"
            layout="${longdate} ${level:upperCase=true} ${message}"
            keepFileOpen="true"
            concurrentWrites="true" />
  </targets>
</nlog>

Now Robot doesn't log to any target. Any idea why?

0

There are 0 best solutions below