NLog 中没有根参数的 Web 服务目标中的 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
支持它,但网络服务目标似乎不太。非常感谢任何帮助。
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>
我想在 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
支持它,但网络服务目标似乎不太。非常感谢任何帮助。
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>