A
A
alexeyborisov752021-03-29 17:16:08
elasticsearch
alexeyborisov75, 2021-03-29 17:16:08

How to set up Nlog for logging to ElasticSearch?

Good afternoon! please tell me how to set up
the Nloga config in the project so that it sends logs to ELK . Now I have Nlog writes everything to files, for example, there is a target

<target name="DebugFile" xsi:type="File" fileName="${logDirectory}Debug${logFilePrefix}"
            archiveFileName="${logDirectory}Debug${archiveFilePrefix}"
            layout="${fileLayout}" />


according to the attached example, I made this "turd"

<target name="elastic" xsi:type="BufferingWrapper" index="AxBranches" uri="http://localhost:9200" flushTimeout="5000">
       layout="$Debug" />


Of course, this does not work, how to do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2021-03-29
@alexeyborisov75

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

<target name="ElasticSearch" xsi:type="BufferingWrapper" flushTimeout="5000">
      <target xsi:type="ElasticSearch" layout="${message}" uri="http://192.168.1.1:9200/" 
                  index="logs-${date:format=yyyy.MM.dd}">
      </target>
</target>

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question