简体   繁体   English

NLog 数据库参数 + .NET Core:JSON 中的所有事件属性?

[英]NLog Database Parameter + .NET Core: all-event-properties in JSON?

I am using the Database target and trying to figure out a way to send all-event-properties as a parameter in JSON format;我正在使用数据库目标并试图找出一种方法以 JSON 格式将all-event-properties作为参数发送; I see that parameter includes a property for "format," but when I do format="json" it doesn't produce the desired effect.我看到该参数包含“格式”的属性,但是当我执行format="json"它不会产生预期的效果。

Here's what I have in my nlog.config file:这是我在 nlog.config 文件中的内容:

<target name="database">
    <parameter name="@properties" layout="${all-event-properties}" format="json" />
</target>

Unfortunately my properties are still getting logged in the format不幸的是,我的属性仍然以这种格式记录

property1=property1, property2=property2, property3=property3

What I'm expecting to see is我期待看到的是

{
    "property1": "property1",
    "property2": "property2",
    "property3": "property3"
}

Please advise.请指教。 Thank you!谢谢!

You can do this:你可以这样做:

<target name="database" type="database">
    <parameter name="@properties">
        <layout type="JsonLayout" includeAllProperties="true" maxRecursionLimit="1" escapeForwardSlash="false" />
    </parameter>
</target>

See also: https://github.com/nlog/nlog/wiki/JsonLayout另见: https : //github.com/nlog/nlog/wiki/JsonLayout

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

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