[英]Serilog does not send logs to Elasticsearch 8
I used ELK stack to log application errors, but Serilog does not log to elasticsearch .我使用ELK堆栈记录应用程序错误,但Serilog不记录到elasticsearch 。
The elasticsearch version that is used is 8.3.2 .使用的 elasticsearch 版本是8.3.2 。
Log configuration in program.cs
: program.cs
中的日志配置:
builder.UseSerilog((hostBuilder, serviceProvider, loggerConfiguration) =>
{
var appSettings = hostBuilder.Configuration.GetSection(nameof(AppSettings)).Get<AppSettings>();
CreateBasicLoggerConfiguration(loggerConfiguration)
.WriteTo.File(logPath, rollingInterval: RollingInterval.Hour)
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(appSettings.ElasticsearchSettings.Uri))
{
IndexFormat = $"َapp-logs-{environment.EnvironmentName.Replace(".","-")}-{DateTimeOffset.Now.LocalDateTime:yyyy-MM}",
AutoRegisterTemplate = true
});
});
And, elasticsearch setting in appsettings.json
:而且, appsettings.json中的
appsettings.json
设置:
"ElasticsearchSettings": {
"Uri" : "http://localhost:9200"
}
The following packages were added and used:添加并使用了以下软件包:
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
<PackageReference Include="Serilog.Enrichers.ClientInfo" Version="1.1.4" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="8.4.1" />
Everything looks ok but there is no log in elastichsearch.一切看起来都不错,但在 elastichsearch 中没有登录。
This issue is because of the current version of Serilog.Sinks.Elasticsearch
serilog sink is not supported elasticsearch version 8.*.这个问题是因为当前版本的
Serilog.Sinks.Elasticsearch
serilog sink 不支持 elasticsearch版本 8.*。
By default, so you need some more configuration.默认情况下,因此您需要更多配置。 I recently faced this issue and wrote an article about it.
我最近遇到了这个问题并写了一篇关于它的文章。 I recommend reading that article and solving your problem.
我建议阅读该文章并解决您的问题。
Try the following config:尝试以下配置:
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(appSettings.ElasticsearchSettings.Uri))
{
IndexFormat = $"َapp-logs-{environment.EnvironmentName.Replace(".","-")}-{DateTimeOffset.Now.LocalDateTime:yyyy-MM}",
AutoRegisterTemplate = true,
OverwriteTemplate = true,
TemplateName = yourTemplateName,
AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7,
TypeName = null,
BatchAction = ElasticOpType.Create
});
Article Link : How to integrate Serilog with Elasticsearch 8 + Kibana文章链接: 如何将 Serilog 与 Elasticsearch 8 + Kibana 集成
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.