简体   繁体   English

NLog中没有root参数的webservice目标中的JsonLayout

[英]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"我想在 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>

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 /> ? Nlog 是否支持直接使用 JsonLayout 而不是包裹在<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. file and console支持它,但 Web 服务目标似乎也不支持。 Any help is greatly appreciated.非常感谢任何帮助。

NLog 4.5 allows you use a parameter without name. NLog 4.5 允许您使用没有名称的参数。 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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