Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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; I see that parameter includes a property for "format," but when I do format="json" it doesn't produce the desired effect.

Here's what I have in my nlog.config file:

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

like image 916
codeMonkey Avatar asked Jan 31 '26 03:01

codeMonkey


1 Answers

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

like image 161
Rolf Kristensen Avatar answered Feb 03 '26 07:02

Rolf Kristensen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!