6

我有一个 ASP.NET Core Web 项目部署到 Azure 并配置了 Application Insights。Insights 可以正常接收请求等数据,但我无法让它显示我的日志。

我正在使用 vanilla Microsoft.Extensions.Logging 框架,并且在控制器操作上记录了一个测试错误

logger.LogError("Test application insights message");

在我设置的 Startup.cs 配置方法中

loggerFactory.AddAzureWebAppDiagnostics();

...并且可以成功看到错误消息出现在 Azure 日志流中:

2017-04-14 11:06:00.313 +00:00 [Error] Test application insights message

但是,我也希望此消息出现在 Application Insights 跟踪中,但无处可寻。我想我需要配置 ILoggerFactory 但不确定如何并且找不到有关该主题的任何文档。

在此先感谢您的帮助

4

2 回答 2

10

万一其他人试图解决这个问题,我得到了我想要的结果,如下所示:

loggerFactory.AddApplicationInsights(app.ApplicationServices);
于 2017-04-30T14:40:56.130 回答
0

对我来说,它只有在我这样指定 InstrumentationKey 时才services.AddLogging有效Startup.cs

services.AddApplicationInsightsTelemetry();

services.AddLogging(builder =>
{
    // Only Application Insights is registered as a logger provider, get the key from appSettings.json file and add application insight
    var instrumentationKey = Configuration.GetValue<string>("ApplicationInsights:InstrumentationKey");
    builder.AddApplicationInsights(instrumentationKey);
});
于 2021-08-02T20:18:38.097 回答