nlog - 使用 NLog 将日志重定向到 json 文件
问题描述
在我的组织中,我们使用 UIPath,而机器人日志记录基于 NLog。默认的 nlog 配置如下所示:
<?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>
它有效,但我们决定将日志也重定向到 json 文件。现在 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">
<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>
现在机器人不会登录到任何目标。知道为什么吗?
解决方案
推荐阅读
- javascript - Mongodb:协会不起作用
- sql - 在 IBM i (V7.3) 上使用 RPG 和 YAJL 或 DB2-SQL 将作为数组接收的整个 Json 文件分解
- laravel - XAMPP:我的本地主机只听我的 Laravel 文件而不是其他非 laravel 文件
- android - 如何在Android上创建具有范围突出显示的自定义形状的进度条?
- cakephp - 未定义的方法 Cake\Utility\Security::cipher()
- r - quantstrat 中的净额交易
- ios - 在 Xcode 中,如果用户在应用程序中执行特定操作,您将如何让视图控制器只能由用户访问?
- jqgrid - jqGrid 免费 multiPageSelect 多选清除 selrrrow
- javascript - 无法获取函数参数javascript
- c# - 使用 Nominatim API 的反向地理编码不起作用