Webservice目标中的JsonLayout,在NLog中没有root参数

我想在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服务目标似乎也不是。非常感谢您的帮助。

0
投票

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>