Ilogger 日志未发送到应用程序洞察

Ilogger logs are not being sent to application insights

我使用的是 .NET 6,并且配置了应用程序洞察。 在我的初创公司中,我有

    services.AddApplicationInsightsTelemetry();
    services.AddApplicationInsightsKubernetesEnricher();

在我的应用程序设置中,我配置了一个检测密钥:

  "ApplicationInsights": {
    "InstrumentationKey": "key"
  }

我还配置了日志级别

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  }
}

但是当我尝试使用 Ilogger 发送自定义消息时,它们没有被发送到应用程序洞察。

    logger.LogWarning("Object with id {id} not found.", id);

在我的控制台中,我看到了各种 AppRequest,但其中 none 包含我放入 Ilogger 中的错误消息。我错过了什么?

我通过将我的包更新到

解决了这个问题
 <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.20.0" />
 <PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="2.0.1" />