1、安装nuget包
NLog.Targets.ElasticSearch
2、调整配置文件Nlog.config
<?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"> <extensions> <add assembly="NLog.Targets.ElasticSearch"/> </extensions> <targets> <!--ElasticSearch保存日志信息--> <target name="elastic" xsi:type="BufferingWrapper" flushTimeout="2000"> <target xsi:type="ElasticSearch" username="elastic" password="123456" uri="https://xxxxxx.com:9200" index="nlog_${date:format=yyyy.MM.dd}" includeAllProperties="true"> <field name="MachineName" layout="${machinename}" /> <field name="Time" layout="${longdate}" /> <field name="level" layout="${level:uppercase=true}" /> <field name="logger" layout="${logger}" /> <field name="message" layout="${message}" /> <field name="processid" layout="${processid}" /> <field name="threadname" layout="${threadname}" /> <field name="stacktrace" layout="${stacktrace}" /> </target> </target> </targets> <rules> <logger name="*" minlevel="DEBUG" writeTo="elastic" /> </rules> </nlog>
标签:配置文件,接入,Nlog,组件,日志,ES From: https://www.cnblogs.com/zacklau/p/16775470.html