如何与Serilog添加Elasticsearch服务相关
我正在使用 Elasticsearch 的 APM 监控我的应用程序。该应用程序包括多个节点,每个节点都有自己的 Elasticsearch 服务。
目前,Elasticsearch 能够将日志与应用程序内创建的事务和跨度关联起来,但它们不与创建它们的服务或节点关联。
我注意到事务中的“服务名称”字段为空日志。
以下是我配置应用程序 Serilog 的方法:
private static readonly Serilog.Core.Logger Serilogger = new LoggerConfiguration()
.Enrich.WithProperty("ApplicationName", "myApp")
.Enrich.FromLogContext()
.WriteTo.Console()
.Enrich.WithElasticApmCorrelationInfo()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri($"http://{StaticAddresses.ElasticIp}:{StaticAddresses.ElasticHttpPort}"))
{
CustomFormatter = new EcsTextFormatter(),
AutoRegisterTemplate = true,
IndexFormat = "myApp",
ModifyConnectionSettings = x => x.BasicAuthentication(ApmConfiguration.ElasticUser, ApmConfiguration.ElasticPswd)
})
.CreateLogger();
有什么方法可以在此处添加包含服务名称的字段吗?我错过了什么吗?
I am monitoring my application using Elasticsearch's APM. This application includes several nodes, each with their own Elasticsearch service.
For now, Elasticsearch is able to correlate logs with transactions and spans created inside our application, but they do not correlate with the service or node that created them.
I noticed that the field "Service Name" is empty in the transaction logs.
Here's how I'm configuring my application's Serilog:
private static readonly Serilog.Core.Logger Serilogger = new LoggerConfiguration()
.Enrich.WithProperty("ApplicationName", "myApp")
.Enrich.FromLogContext()
.WriteTo.Console()
.Enrich.WithElasticApmCorrelationInfo()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(quot;http://{StaticAddresses.ElasticIp}:{StaticAddresses.ElasticHttpPort}"))
{
CustomFormatter = new EcsTextFormatter(),
AutoRegisterTemplate = true,
IndexFormat = "myApp",
ModifyConnectionSettings = x => x.BasicAuthentication(ApmConfiguration.ElasticUser, ApmConfiguration.ElasticPswd)
})
.CreateLogger();
Is there any way I can add a field including the Service Name here? Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现问题是什么。
ecstextFormatter()
不包括Service.name,Container.ID或Host.name。您需要手动添加它。https:> https: //discuss.elastic.co/t/logs-do-not-appear-in-apm--loge-correlation-info-ispresent/289720
I've found what the problem is. The
EcsTextFormatter()
does not automatically include the service.name, container.id or host.name of your application. You need to add it manually.https://discuss.elastic.co/t/logs-do-not-appear-in-apm-although-correlation-info-is-present/289720