2

我正在使用提供的 asp.net 核心日志记录并配置了应用程序洞察力。我可以在应用程序洞察力中看到未处理的异常,但在应用程序洞察力中看不到logger.LogInformation("testing")任何地方。我确实在日志流中看到了日志。

此外,我没有在 Visual Studio Application Insights 屏幕中看到日志。我创建了一个 hello world 应用程序,它表明您在应用程序洞察力中看不到日志。

https://github.com/devlife/AppInsightsSandbox

有什么想法吗?

在此处输入图像描述

4

1 回答 1

3

您能否描述一下您是如何启用 ApplicationInsights 来捕获 ILogger 的?如果您使用的是 SDK 的最新 beta 版本,则无需显式操作即可捕获 ILogger 跟踪。但它只会捕获警告或以上级别的日志。

按照此文档配置应用程序洞察力以捕获不同的日志级别。 https://docs.microsoft.com/en-us/azure/azure-monitor/app/ilogger#control-logging-level

如果您未使用最新的 SDK,则需要根据上述文档明确启用应用程序洞察力以捕获 ilogger 日志。在这里,您还需要配置日志记录级别,以便捕获 LogInformation。

.ConfigureLogging(
            builder =>
            {                
                builder.AddApplicationInsights("ikey");
  builder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>("", LogLevel.Information); // this will capture Info level traces and above.
            }
于 2019-05-08T22:00:20.877 回答