2

鉴于此 appsettings.json

{
  "ApplicationInsights": {
    "InstrumentationKey": "foobar",
    "LogLevel": {
      "Default": "Debug"
    }
  },
  "Logging": {
    "LogLevel": {
      "Default": "Debug"
    }
  },
  "AllowedHosts": "*"
}

而这来自startup.cs

public void ConfigureServices(IServiceCollection services)
{
    var appSettingsSection = Configuration.GetSection("TD");
    var appSettings = new AppSettings();
    new ConfigureFromConfigurationOptions<AppSettings>(appSettingsSection).Configure(appSettings);
    services.Configure<AppSettings>(appSettingsSection);

    services.AddApplicationInsightsTelemetry();

    services.AddTransient<IMyService, MyService>();
    services.AddControllersWithViews();
    services.AddSpaStaticFiles(configuration =>
    {
        configuration.RootPath = "ClientApp";
    });
}

为什么在我的 AI 输出中仍然只看到严重、错误和警告?

例如来自控制器的任意日志

public async Task<IActionResult> MyAction(string foobar)
{
    Logger.LogDebug($"Ilogger debug {foobar}");
    Logger.LogInformation($"Ilogger info {foobar}");
    Logger.LogWarning($"Ilogger warning {foobar}");
    Logger.LogError($"Ilogger error {foobar}");
    Logger.LogCritical($"Ilogger critical {foobar}");
}

根据这里的微软文档

当您通过以下任一方法打开常规 Application Insights 监视时,ApplicationInsightsLoggerProvider 在 Microsoft.ApplicationInsights.AspNet SDK 版本 2.7.1(及更高版本)中默认启用:

  • 通过调用 UseApplicationInsights 扩展方法 onIWebHostBuilder(现已过时)
  • 通过调用 IServiceCollection 上的 AddApplicationInsightsTelemetry 扩展方法

所以我对为什么没有输出调试/信息跟踪有点迷茫。

appsettings.development.json 中没有覆盖或日志记录设置。

我正在使用 AppInsights SDK 2.13.1。

ASP.NET 核心 3.1。

4

1 回答 1

2

有问题appsettings.json(如果您确定没有其他地方覆盖日志记录级别)。应用程序洞察的日志级别应放置在Logging.json 文件中的元素中(请参阅此处的官方文档)。

正确的应该是这样的:

{
  "ApplicationInsights": {
    "InstrumentationKey": "xxxxx"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Debug"
    },
    "ApplicationInsights": {
      "LogLevel": {
        "Default": "Debug"
      }
    }
  },
  "AllowedHosts": "*"
}

和测试结果:

在此处输入图像描述

于 2020-03-31T01:55:17.863 回答