asp.net 为OpenTelemetry日志事件的主体创建模板

ckx4rj1h  于 5个月前  发布在  .NET
关注(0)|答案(1)|浏览(71)

我正在运行一个ASP.NET核心应用程序,使用的是dotnetopentelemetry客户端。
应用程序将所有事件发送到OpenTelemetry Collector的示例,然后将事件存储在ElasticSearch和Prometheus中。
现在,我在ElasticSearch中获取日志事件,因此在Kibana中可见。
一个ES文档主体属性可能如下所示

Executed action method {ActionName}, returned result {ActionResult} in {ElapsedMilliseconds}ms.

字符串
可以在这个链中的东西被配置为应用此模板与事件的属性,IE这样我就可以在日志中读取Executed action method Corp.Service.Controllers.Controller.StoreEvent (Corp.Service), returned result Microsoft.AspNetCore.Mvc.NoContentResult in 4.32ms.以及?

j0pj023g

j0pj023g1#

设置OpenTelemetry时需要配置IncludeFormattedMessage参数。
举例来说:

builder.Logging.AddOpenTelemetry(configure =>
{
    configure.IncludeFormattedMessage = true;
    
    configure.AddConsoleExporter();
});

字符串

相关问题