[英]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.