首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NLog Truncate语法

NLog Truncate语法
EN

Stack Overflow用户
提问于 2020-10-05 23:36:14
回答 1查看 111关注 0票数 0

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

代码语言:javascript
复制
<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" />

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

代码语言:javascript
复制
(^(?:\S+\s+\n?){0, 20000}) 
(?\=.\{20000\}).+

有人能告诉我我做错了什么吗?如何将截断值设置为20000?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-07 02:26:12

这对我来说很有效:

代码语言:javascript
复制
<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个字符:

代码语言:javascript
复制
var test = string.Empty.PadLeft(40000, '*');
NLog.LogManager.GetLogger("test").Info("Doing hard work! {Action}", test);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64211799

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档