1
votes

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.

1
@RolfKristensen Is this feature not yet merged to master? - user3205479
No it is an adventure up for graps, ready for anyone with guts and courage. - Rolf Kristensen

1 Answers

0
votes

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>