ecs-dotnet icon indicating copy to clipboard operation
ecs-dotnet copied to clipboard

[FEATURE] NLog - Ability to add custom fields to the log event.

Open yorondevops opened this issue 3 years ago • 2 comments

Hi,

Would be great if there was a way to dynamically serialize key-value pairs from the MDLC as top-level fields in the event body, without placing them under the metadata field.

For example: Using the latest version of Elastic.CommonSchema.NLog, an MDLC holding the key-value pairs "foo":"bar" and "abc":123 would be serialized into the event like this:

{
    "metadata" : {
        "foo": "bar",
        "abc": 123
    }
}

I think an option should exist to have them serialized directly at the top level of the event like this:

{
    "foo": "bar",
    "abc": 123
}

On issues similar to this (#104 and #141) others have already suggested using a logstash or ingest pipeline to rename the fields. I find that for larger scale multi-tenant setups, it works out much better to let each app owner get their desired fields right in their app "at the edge".

This can help by simplifying the process ("what you write is what you get"), giving developers more freedom to make changes independently, and removing the additional overhead of having to maintain one or more pipelines.

yorondevops avatar Jun 22 '21 05:06 yorondevops

See also https://github.com/NLog/NLog/issues/4982 for an example of customizing your own NLog JsonLayout that outs JSON in Ecs-Common-Schema-Format. Where you are free to customize it in whatever direction you like.

snakefoot avatar Aug 04 '22 19:08 snakefoot