0
votes

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

1
Try removing the line <logger name="*" minlevel="Trace" writeTo="file" /> from your <rules> - Priyank Panchal
@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
@Julian I have not find any extra info in your suggested link. - H.Neo
There should be something in the internal log. - Julian

1 Answers

3
votes

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>