假设有这个 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}");
}
根据 Microsoft 文档 这里,在启用常规应用程序性能监视的情况下,Microsoft.ApplicationInsights.AspNet SDK 版本 2.7.1(及更高版本)默认启用 ApplicationInsightsLoggerProvider。可以通过以下两种方法之一来开启应用程序性能监视:
- 通过对 IWebHostBuilder 调用 UseApplicationInsights 扩展方法(现已过时)。
- 通过对 IServiceCollection 调用 AddApplicationInsightsTelemetry 扩展方法。
在 appsettings.development.json 中没有覆盖或记录设置。
我正在使用 AppInsights SDK 2.13.1。
Asp NET Core 3.1。