繁体   English   中英

NLog中没有root参数的webservice目标中的JsonLayout

[英]JsonLayout in webservice target without root parameter in NLog

我想在 Web 服务目标中有 JsonLayout 以便我可以使用includeAllProperties="true"

<target xsi:type="WebService"
            name="ws"
            url="http://localhost:59802/api/hello/indexer"
            protocol="JsonPost"
            encoding="UTF-8">
<parameter name="root">
  <layout xsi:type="JsonLayout" includeAllProperties="true">
     <attribute name="Level" layout="${level}" />
     <attribute name="Timestamp" layout="${longdate}" />
     <attribute name="Message" layout="${message}" />
  </layout>
</parameter>
</target>

这将创建以下输出

{ "root" : { "level" : "info", "message" : "xxx", "event1" : "aaa" } }

其实,我想有以下

{ "level" : "info", "message" : "xxx", "event1" : "aaa" }

Nlog 是否支持直接使用 JsonLayout 而不是包裹在<parameter /> 或者有什么方法可以破解并实现此输出? file and console支持它,但 Web 服务目标似乎也不支持。 非常感谢任何帮助。

NLog 4.5 允许您使用没有名称的参数。 像这样:

<target xsi:type="WebService"
            name="ws"
            url="http://localhost:59802/api/hello/indexer"
            protocol="JsonPost"
            encoding="UTF-8">
<parameter name="">
  <layout xsi:type="JsonLayout" includeAllProperties="true">
     <attribute name="Level" layout="${level}" />
     <attribute name="Timestamp" layout="${longdate}" />
     <attribute name="Message" layout="${message}" />
  </layout>
</parameter>
</target>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM