You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 8集成Elastic APM后Debug日志无法显示求助

.NET 8 + Serilog + Elastic APM 无法输出Debug级日志问题

原本.NET 8应用使用Serilog日志组件,新增Elastic APM对接Kibana后,本地日志文件、控制台及Kibana均无法查看Debug级日志。已按官方文档配置最新版本,也尝试过已弃用的旧版,但都没有效果。

appsettings.json 配置

"Serilog": {
  "Using": [
    "Serilog.Sinks.Console",
    "Serilog.Sinks.File",
    "Serilog.Enrichers.CorrelationId"
  ],
  "MinimumLevel": {
    "Default": "Debug",
    "Override": {
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information",
      "System": "Warning",
      "Elastic.Apm": "Debug"
    }
  },
  "WriteTo": [
    {
      "Name": "Console",
      "Args": {
          "restrictedToMinimumLevel": "Debug"
        }
      },
      {
        "Name": "File",
        "Args": {
          "path": "Logs/Application.log",
          "restrictedToMinimumLevel": "Debug"
        }
      }
  ],
...
"ElasticApm": {
  "CloudProvider": "none",
  "VerifyServerCert": false,
  "CaptureBody": "all",
  "Instrument": "true",
  "ErrorOnAbortedRequests": "true",
  "ServiceName": "ApplicationName",
  "DisableMetrics": "system.cpu.total.norm.pct, system.process.cpu.total.norm.pct",
  "LogLevel": "Debug"
},
"Logging": {
  "LogLevel": {
    "Default": "Debug",
    "Microsoft.AspNetCore": "Warning",
    "Elastic.Apm": "Debug"
  }
}

日志器代码配置

var loggerConfiguration = new LoggerConfiguration()
    .Enrich.FromLogContext()
    .Enrich.WithProperty("Environment", environment.EnvironmentName)
    .Enrich.WithProperty("Application", configuration["ElasticApm:ServiceName"])
    .MinimumLevel.Debug()
    .WriteTo.Console()
    .WriteTo.Elasticsearch(new[] { new Uri(configuration["Elastic:Url"]!) }, options =>
    {
        options.DataStream = new DataStreamName(
            "logs",
            configuration["ElasticApm:ServiceName"]!,
            environment.EnvironmentName.ToLower());
    }, transport =>
    {
        transport.Authentication(new ApiKey(configuration["Elastic:ApiKey"]!));
        transport.ServerCertificateValidationCallback((o, certificate, chain, errors) => true);
    });

已在多处设置Debug日志级别,根据官方文档,只需在Logging:LogLevel:Default、Logging:LogLevel:Elastic.Apm或ElasticApm:LogLevel中设置即可,但尝试后仍无效果,希望能得到解决帮助,如需更多信息请告知。


内容的提问来源于stack exchange,提问作者milch

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 06:03:14