0

我正在更改 UiPath 的 NLog.config 文件。我想将截断值增加到 20000,并且我尝试了以下语法,但它不起作用。

<variable name="truncated_message" value="${replace:replaceWith=...TRUNCATED:regex=true:inner=${message}:searchFor=^[\s\S]{20000}}"/>
<target type="File" name="WorkflowLogFiles" fileName="${WorkflowLoggingDirectory}/${shortdate}_Execution.log" layout="${time} ${level} ${truncated_message}" keepFileOpen="true" openFileCacheTimeout="5" concurrentWrites="true" encoding="utf-8" writeBom="true" />

我也尝试过遵循正则表达式,但它们对我不起作用

(^(?:\S+\s+\n?){0, 20000}) 
(?\=.\{20000\}).+

谁能告诉我我做错了什么以及如何将截断值设置为 20000?

4

1 回答 1

2

这对我有用:

<nlog>
   <variable name="truncated_message_new" value="${message:truncate=20000}" />
   <variable name="truncated_message_old" value="${trim-whitespace:inner=${message:padding=-20000:fixedLength=true}}" />

   <targets>
      <target type="File" name="WorkflowLogFiles" fileName="C:\temp\nlog/${shortdate}_Execution.log" layout="${time} ${level} ${truncated_message_old}" keepFileOpen="true" openFileCacheTimeout="5" concurrentWrites="true" encoding="utf-8" writeBom="true" />
   </targets>

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

它只保存 20000 个字符:

var test = string.Empty.PadLeft(40000, '*');
NLog.LogManager.GetLogger("test").Info("Doing hard work! {Action}", test);
于 2020-10-06T18:26:11.890 回答