【问题标题】:NLog Truncate syntaxNLog 截断语法
【发布时间】:2020-10-05 15:36:14
【问题描述】:

我正在更改 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?

【问题讨论】:

  • 这个问题的重复:stackoverflow.com/a/55941565/193178 ?你可以使用${message:truncate=20000}
  • 这能回答你的问题吗? NLog auto truncate messages
  • @RolfKristensen 是的,我已经将其作为 它不能正常工作。
  • @Julian 我也试过这个,但我不知道为什么它不适合我。能否请您告诉我如何查看 Nlog 的版本?
  • @Maryam 如果您不知道如何升级 NLog nuget-package,那么您可以随时尝试传统方法:${trim-whitespace:inner=${message:padding=-20000:fixedLength=true}}

标签: nlog uipath truncate-log


【解决方案1】:

这对我有用:

<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);

【讨论】:

  • 我尝试了 5000 并且它正在工作。另外,我刚刚知道 UiPath 不允许超过 10,000 个字符,所以这就是为什么它不能使用 20,000 个限制。非常感谢您的帮助,我非常感谢 :) 我将其标记为解决方案
  • 想一想我们可以在 Nlog 中设置的最大截断限制是多少?
  • 我猜它是 1 或 2 GB。但你可能会先达到其他有趣的限制。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-15
相关资源
最近更新 更多