Logstash提供了多种监听日志打印的方式,而Nlog也提供了多种输出日志的方式,当Nlog的输出配置与Logstash的输入配置相对应,就能够让Nlog打印出来的日志都存储到Elasticsearch中
以下介绍3种配置方式:
1) 文件
Logstash:
代码语言:javascript复制input {
file {
path => "D:/Log/Application/*Log.txt"
type => "Application"
}
}
Nlog:
代码语言:javascript复制<targets>
<target xsi:type="File" name="file" filename="D:/Log/Application/${shortdate}Log.txt" layout="${longdate} ${uppercase:${level}} ${message}"/>
</targets>
2) tcp
Logstash:
代码语言:javascript复制input{
tcp{
port => 8001
type => "TcpLog"
}
}
Nlog:
代码语言:javascript复制<targets>
<target xsi:type="Network" name="tcp" address="tcp://127.0.0.1:8001" layout="${longdate} ${uppercase:${level}} ${message}"/>
</targets>
3) udp
Logstash:
代码语言:javascript复制input{
udp{
port => 8002
type => "UdpLog"
}
}
Nlog:
代码语言:javascript复制<targets>
<target xsi:type="Network" name="udp" address="udp://127.0.0.1:8001"
layout="${longdate} ${uppercase:${level}} ${message}"/>
</targets>