简体   繁体   中英

JsonLayout in webservice target without root parameter in NLog

I would like to have JsonLayout in web service target so that I can use 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>

This creates the following output

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

Actually, I would like to have as following

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

Does Nlog support to directly use JsonLayout instead of wrapping in <parameter /> ? Or there any ways to hack around and achieve this output? file and console support it but web service target does not seem too. Any help is greatly appreciated.

NLog 4.5 allows you use a parameter without name. Like this:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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