C# NLog使用Json布局添加反斜杠
我无法找到一种方法,告诉NLog在没有反斜杠的情况下正确打印JSON 这是我的Nlog.config:C# NLog使用Json布局添加反斜杠,c#,json,nlog,C#,Json,Nlog,我无法找到一种方法,告诉NLog在没有反斜杠的情况下正确打印JSON 这是我的Nlog.config: 然而,当它打印到文件时,我得到了以下示例: "Payload": "{\"name\":\"value\",\"surname\":\"value\"}" 知道如何修复它吗?它逃过了负载,因为它不知道它已经是JSON了 您可以使用encode=“false”禁用此功能,
然而,当它打印到文件时,我得到了以下示例:
"Payload": "{\"name\":\"value\",\"surname\":\"value\"}"
知道如何修复它吗?它逃过了负载,因为它不知道它已经是JSON了 您可以使用
encode=“false”
禁用此功能,如下所示:
<attribute name="Payload" encode="false" escapeForwardSlash="false" layout="${aspnet-request-posted-body:when=level==LogLevel.Trace or level==LogLevel.Error or level==LogLevel.Fatal}"/>
它逃过了负载,因为它不知道它已经是JSON了
您可以使用encode=“false”
禁用此功能,如下所示:
<attribute name="Payload" encode="false" escapeForwardSlash="false" layout="${aspnet-request-posted-body:when=level==LogLevel.Trace or level==LogLevel.Error or level==LogLevel.Fatal}"/>
如果您可以确保HttpRequest ContentType为application/json
,则可以随机选择:
<layout xsi:type="JsonLayout">
<attribute name="Properties" encode="false">
<layout type='JsonLayout' includeAllProperties="true" maxRecursionLimit="10">
<attribute name="Payload" encode="false" layout="${when:when='${aspnet-request-contenttype}'=='application/json':inner=${aspnet-request-posted-body}}" />
<attribute name="Payload" layout="${when:when='${aspnet-request-contenttype}'!='application/json':inner=${aspnet-request-posted-body}}" />
</layout>
</attribute>
</layout>
如果您能确保HttpRequest ContentType为application/json
,请随意选择:
<layout xsi:type="JsonLayout">
<attribute name="Properties" encode="false">
<layout type='JsonLayout' includeAllProperties="true" maxRecursionLimit="10">
<attribute name="Payload" encode="false" layout="${when:when='${aspnet-request-contenttype}'=='application/json':inner=${aspnet-request-posted-body}}" />
<attribute name="Payload" layout="${when:when='${aspnet-request-contenttype}'!='application/json':inner=${aspnet-request-posted-body}}" />
</layout>
</attribute>
</layout>
如果属性被添加为消息属性,又会怎样?这意味着什么?请编辑您的问题或提出一个新问题,因为实际上不允许提出多个问题。如果属性作为消息属性添加,会怎么样?这意味着什么?请编辑您的问题或提出新问题,因为实际上不允许提出多个问题