【发布时间】:2021-05-02 07:41:52
【问题描述】:
我正在关注 ELK 上的这篇文章:Building Logging System in Microservice Architecture with ELK Stack and Serilog .NET Core,在这个架构中,serilog 记录到 Logstash,然后将 logstash 推送到 Elastic 搜索,如果无法访问弹性搜索或者如果 logstash 服务关闭或者如果网络宕机或系统宕机,简而言之,我要去哪里,如何确保我的日志在所有情况下都不会丢失,日志也应该可以离线使用,我想先存储在日志文件中然后处理从文件到弹性搜索的日志,但是文件会在一段时间内增长,然后我必须注意没有重复的消息并且消息也需要删除,最重要的是没有死锁类型关于读写文件的情况,能否请您帮我了解一下ELK是否会照顾,如果我使用fluend或fluentbit而不是logstash,它们会更好吗??
代码:
var log = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.Http("http://localhost:8080")
.CreateLogger();
while (true)
{
var customer = Customer.Generate();
log.Information("{@customer} registered", customer);
Thread.Sleep(1000);
}
输出:
[13:56:02 INF] {"FirstName": "Lourdes", "LastName": "Kreiger", "SSNumber": "350-11-7869", "$type": "Customer"} registered
[13:56:03 INF] {"FirstName": "Desmond", "LastName": "Balistreri", "SSNumber": "929-58-1854", "$type": "Customer"} registered
...
使用 ELK 发送日志
Http输入监听端口8080
input {
http {
#default host 0.0.0.0:8080
codec => json
}
}
# Separate the logs
filter {
split {
field => "events"
target => "e"
remove_field => "events"
}
}
# Send the logs to Elasticsearch
output {
elasticsearch {
hosts => "elasticsearch:9200"
index=>"customer-%{+xxxx.ww}"
}
}
【问题讨论】:
标签: c# elasticsearch logstash serilog fluentd