0

I am using NLog to write logs to file, which is working fine. Now I want to write logs to Elasticsearch, so I added NLog.Targets.ElasticSearch in nugets package and I configured my Nlog.config file. Unfortunately, I can't see any log information while calling http://localhost:9200/_search

In NLog.config, I added extension and targets for 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>

I expect Trace type NLog should be written in Elasticsearch. Am I missing something in the config file?

By the way, I checked this doc for parameters: https://github.com/ReactiveMarkets/NLog.Targets.ElasticSearch/wiki

Pang
  • 9,564
  • 146
  • 81
  • 122
H.Neo
  • 85
  • 1
  • 8
  • Try removing the line `` from your `` – prinkpan Jun 12 '19 at 19:13
  • Please check https://github.com/nlog/nlog/wiki/Internal-logging. – Julian Jun 12 '19 at 20:12
  • @PriyankPanchal as I mentioned above I also write log in file, just above Nlog configuration I have not added that target parts, that part working fine. Anyway , I also did what you suggested, I comment that part, again not working. – H.Neo Jun 12 '19 at 20:48
  • @Julian I have not find any extra info in your suggested link. – H.Neo Jun 12 '19 at 20:48
  • There should be something in the internal log. – Julian Jun 12 '19 at 21:32
  • On error, it's writing to the internal log, see https://github.com/markmcdowell/NLog.Targets.ElasticSearch/blob/9c73c15e6929ca2f7c6324aa77a4876b00e72556/src/NLog.Targets.ElasticSearch/ElasticSearchTarget.cs#L167-L194 – Julian Jun 12 '19 at 21:34
  • @Julian , I am also doing internal logging using NLog. I just want do integration with ElasticSearch. As far as I know, if I successfully integrate, there is no need extra I should do for ES. While I logging , it automatically send to elasticSearch and I can see while calling http://localhost:9200/_search . For detail info , you can see https://damienbod.com/2016/08/20/asp-net-core-logging-with-nlog-and-elasticsearch/ – H.Neo Jun 12 '19 at 21:45
  • OK. I hoped for a clear error message. :( – Julian Jun 12 '19 at 21:54
  • You got this working as I your newer (and related) question has been answered? https://stackoverflow.com/questions/56683912/index-format-change-daily-to-weekly – Julian Jun 20 '19 at 20:23
  • @Julian I found my answer for this post , and added below solution. thanks for your attention. – H.Neo Jun 21 '19 at 08:53

1 Answers1

3

I just added BufferingWrapper type and it worked. Some references to read:

Additionally, please check ElasticSearch.Net latest version in NuGet package.

You can find NLog configuration for Elasticsearch below, which is working fine for me:

<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>
Pang
  • 9,564
  • 146
  • 81
  • 122
H.Neo
  • 85
  • 1
  • 8