使用NLog 4.5将结构化数据记录到Elastic Search中不能提供在字段中查询的功能 [英] Log Structured data to Elastic Search by using NLog 4.5 doesn't provide the ability to query in the fields

查看:293
本文介绍了使用NLog 4.5将结构化数据记录到Elastic Search中不能提供在字段中查询的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用NLog,当我将对象/结构化数据"记录到Elastic Search中时,无法对其进行查询的存储在其中,请查看下图:

Using NLog, when I log object/"structured data" to Elastic Search it stored in away that I can not make query on it, Please look to below image:

      <target xsi:type="ElasticSearch"
        name="MyElasticTarget"
        uri="url"
        requireAuth="true"
        username="MyUser"
        password="MyPass"
        Index="MyIndex-${date:format=yyyy.MM.dd}"
        >
        <layout xsi:type="JsonLayout" type='JsonLayout' IncludeAllProperties='true'>
          <attribute name='LogMessage' layout='${MySimpleClass:raw=true}' />
        </layout>
      </target>

  </targets>

代码是:

  var _simpleObj = new MySimpleClass(5, "my structured Simple obj", "Sometype");
            var logger = LogManager.GetLogger("Example");
            logger.Info("{@MySimpleClass}", _simpleObj );

当我使用SeriLog记录/存储相同的结构化数据时,我可以进行查询,因为我的对象字段不在消息范围之内,并且作为字段,请查看下图:

While When I log/store the same Structured data by using SeriLog, I can do query because I have the fields of object out of the message scope and as fields, please look to below image:

有什么主意,我如何记录结构化数据(对象)以便能够使用NLog进行查询?

Any Idea how I can log structured data (objects) in be able to query them by use NLog?

推荐答案

您是否尝试为includeAllProperties 属性.Targets.ElasticSearch"rel =" nofollow noreferrer> NLog目标:

Have you tried to enable the includeAllProperties property for the NLog target:

<target xsi:type="ElasticSearch" includeAllProperties="true" />

您还可以添加自己的自定义字段:

You can also add your own custom fields:

<target xsi:type="ElasticSearch" includeAllProperties="true">
     <field name="messageTemplate" layout="${message:raw=true}" />
</target>

这篇关于使用NLog 4.5将结构化数据记录到Elastic Search中不能提供在字段中查询的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆