如何在Nlog.Web.AspNetCore中省略转义“/”

问题描述 投票:1回答:1

我正在使用Nlog.Web.AspNetCore 4.8来登录文件。在Nlog.config中,我将布局配置为JsonLayout。问题是最终结果包含反斜杠以逃避原始错误消息中的“/”。除非明确说明,否则有没有办法配置NLog省略转义某些字符?

这是我的JsonLayout配置:

<target xsi:type="File" name="ownFile-web" fileName="${logDirectory}/logs.txt" >
  <layout type='JsonLayout' includeAllProperties="true"  maxRecursionLimit="20" >
    <attribute name="time" layout="${longdate}" />
    <attribute name="level" layout="${level}" />
    <attribute name="logger" layout="${logger}" />
    <attribute name="message" layout="${message}" />
  </layout >
</target>

以下是结果:

{ "time": "2019-03-01 01:12:07.2239", "level": "Error", "logger": "Scheduler.Api.Startup", "message": "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server\/Instance Specified)" }

我宁愿结果如下:

{ "time": "2019-03-01 01:12:07.2239", "level": "Error", "logger": "Scheduler.Api.Startup", "message": "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)" }
asp.net-core nlog
1个回答
1
投票

这看起来像编码问题。试试下面的内容。

 <attribute name="message" layout="${message}" encode="false"/>

我还建议在布局文件中包含实际的异常

 <attribute name="${exception}" layout="${exception:format=toString}" />
© www.soinside.com 2019 - 2024. All rights reserved.