.NET Core 中 NLog 与 Elasticsearch 的集成问题

Integration problem NLog with Elasticsearch in .NET Core

我正在使用 NLog 将日志写入文件,工作正常。现在我想将日志写入 Elasticsearch,所以我在 nugets 包中添加了 NLog.Targets.ElasticSearch 并配置了我的 Nlog.config 文件。不幸的是,我在调用 http://localhost:9200/_search

时看不到任何日志信息

在 NLog.config 中,我为 Elasticsearch 添加了扩展和目标:

   <extensions>
    <add assembly="NLog.Extended" />
    <add assembly="NLog.Targets.ElasticSearch"/>
   </extensions>

<targets>
  <target xsi:type="ElasticSearch" 
        name="elastic" 
        layout="${logger} | ${threadid} | ${message}" 
        includeAllProperties="true" 
        uri="http://localhost:9200"/>
 </targets>

<rules>
    <logger name="*" minlevel="Trace" writeTo="file" />
    <logger name="*" minlevel="Trace" writeTo="elastic" />
</rules>

我希望Trace类型的NLog应该写在Elasticsearch中。我在配置文件中遗漏了什么吗?

顺便说一下,我检查了这个文档的参数:https://github.com/ReactiveMarkets/NLog.Targets.ElasticSearch/wiki

我刚刚添加了 BufferingWrapper type 并且成功了。一些参考阅读:

此外,请检查 ElasticSearch.Net NuGet 包中的最新版本。

您可以在下面找到 Elasticsearch 的 NLog 配置,这对我来说工作正常:

<extensions>
    <add assembly="NLog.Extended" />
    <add assembly="NLog.Targets.ElasticSearch"/>
</extensions>

<target xsi:type="BufferingWrapper" name="ElasticSearch"
        flushTimeout="5000">
   <target xsi:type="ElasticSearch"          
          uri="http://localhost:9200" 
          includeAllProperties ="true">
   </target>
 </target>

<rules>
    <logger name="*" minlevel="Trace" writeTo="file" />
    <logger name="*" minlevel="Trace" writeTo="ElasticSearch" />
</rules>