简体   繁体   中英

Using Nlog logger with ECS layout, in kibana the json object appear as a string instead of multiple properties

I'm working on some .Net framework application and i've been asked to send the logs to elasticsearch using kibana as the UI. To have something that is standardized i have to implement ECS (Elastic Common Schema).

Looking at the example we have on ECS github we only have to implement it on the following way:

在此处输入图片说明

Instead of sending to console, like we have on the example i send it to elastic search

在此处输入图片说明

The output from it, would be a nice Json object...

Maybe it is expected that on kibana we would see something like the following ( Kibana - Discover ):

在此处输入图片说明

Looking at that, probably the Json Object is supposed to be treated as a string and everything goes inside the message property, but that is not what i'm looking for, i want that json to be divided in many properties.

Since i'm new to Elastic stack world, i've tried to create a template inside the Index Management page and the performing there manual mappings like message._metadata.url to not treat some properties as part of the string but without success.

I'm having trouble finding useful information to solve this problem, can anyone give an hint?

UPDATE:

I found the property enableJsonLayout="true" that we can put on the target of Nlog that indeed turns whats on the Json layout as properties on ElasticSearch which is good.

在此处输入图片说明

Is this the right way to use ECS? How can i add aditional properties?

When you enable this enableJsonLayout="true" then it means that the configured Layout has to handle everything. For EcsLayout then you can find the documentation here:

https://github.com/elastic/ecs-dotnet/tree/master/src/Elastic.CommonSchema.NLog

EcsLayout will by default include all LogEvent Properties as metadata. See alsohttps://github.com/NLog/NLog/wiki/How-to-use-structured-logging

But you can explicit add extra metadata-items:

<layout xsi:type="EcsLayout">
   <metadata name="MyProperty" layout="MyPropertyValue" />
</layout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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