一、elk的安装教程
参考链接:https://www.8kiz.cn/archives/2623.html
二、netcore 接入elk
1、NLog接入
NLog日志输出到logstash里,使用方式
①配置logstash,添加tcp端口输入
input { tcp { port => 5044 type => "service1-log" } }
②重启logstash
sudo systemctl restart logstash
③添加NLog包,nuget包里安装
④修改NLog.config配置文件
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <targets async="true"> <target name="logstash" xsi:type="Network" address="tcp://IP:端口" keepConnection="false" layout="[${uppercase:${level}}] [${longdate}] [${logger}] | ${message} ${exception}" /> </targets> <rules> <logger name="*" level="Info,Error" writeTo="logstash" /> </rules> </nlog>
2、log4net接入
log4net日志输出到logstash里,使用方式
①配置logstash,添加udp端口输入
input { udp { port => 5044 type => "service1-log" } }
②重启logstash
sudo systemctl restart logstash
③添加log4net.ElasticSearch包
④添加log4net.config配置文件
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/> </configSections> <log4net> <appender name="UdpAppender" type="log4net.Appender.UdpAppender"> <remoteAddress value="IP" /> <remotePort value="端口" /> <encoding value="UTF-8" /> <layout type="log4net.Layout.PatternLayout, log4net"> <conversionPattern value="%-5level %date [%-5.5thread] %-40.40logger - %message%newline" /> </layout> </appender> <root> <level value="ALL" /> <appender-ref ref="UdpAppender" /> </root> </log4net> </configuration>
标签:log4net,elk,netcore,接入,添加,NLog,logstash From: https://www.cnblogs.com/ccprince/p/18080868