我正在尝试使用NLog.Targets.ElasticSearch使用NLog登录Elasticsearch。索引已成功创建,但未找到日志数据。
我的NLog配置:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true">
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
<add assembly="NLog.Targets.ElasticSearch"/>
</extensions>
<targets async="true">
<target name="elastic" xsi:type="ElasticSearch" index="logs-elasticsearch-sample" documentType=""
uri="http://localhost:9200" includeAllProperties="true"
layout ="API:logs-elasticsearch-sample|${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" >
</target>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="elastic" />
</rules>
</nlog>
字符串
.net 6 NLog.Targets.ElasticSearch v7.7.0 NLog.Web.AspNetCore v4.14.0 Elasticsearch v7.17.1(也尝试过v8.1.0)
原始教程:https://dev.to/majidqafouri/writing-logs-into-elastic-with-nlog-elk-and-net-5-0-246c
老实说,我是elasticsearch的新手,所以我可能做错了什么,但步骤相当简单。https://www.elastic.co/guide/en/kibana/8.1/docker.htmlhttps://www.elastic.co/guide/en/kibana/7.17/docker.html
在我的测试中,我使用Docker容器为elasticsearch和kibana.还尝试使用控制台应用程序(.net core 3.1)记录日志,同时以编程方式为Nlog创建弹性目标,我得到了相同的结果。
顺便说一下,我可以很好地从kibana创建和查询数据。
2条答案
按热度按时间tnkciper1#
因此,对于任何使用NLog. Targets. ElasticSearch有问题的人来说,有几点需要考虑:
1.如果索引以logs-* 开头,请确保为它创建一个优先级更高索引模板:https://discuss.elastic.co/t/cant-create-indices/254204/3
rhfm7lfc2#
将此配置添加到NLog.config以获取查找问题的日志
字符串
如果有任何问题日志弹性可以找到'c:\工作\log.txt'