gpt4 book ai didi

.net - 应用程序洞察 : loggerFactory. AddApplicationInsights 在 .net core 2.2.0 中已弃用

转载 作者:行者123 更新时间:2023-12-02 03:16:38 28 4
gpt4 key购买 nike

在.net core 2.1.1中,使用以下方式注册应用程序见解:

public void ConfigureServices(IServiceCollection services)
{
...
services.AddApplicationInsightsTelemetry(Configuration); //register InstrumentationKey
...
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
...
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Information);
...
}

但是,当我将其包含在 .net core 2.2.0 中时,我收到警告:

'ApplicationInsightsLoggerFactoryExtensions.AddApplicationInsights(ILoggerFactory, IServiceProvider, LogLevel)' is obsolete: 'Use Microsoft.Extensions.Logging.ApplicationInsightsLoggingBuilderExtensions.AddApplicationInsights from Microsoft.Extensions.Logging.ApplicationInsights package'

我已经包含了包Microsoft.Extensions.Logging.ApplicationInsights包并像这样使用:

 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
ApplicationInsightsLoggingBuilderExtensions.AddApplicationInsights(...//some params//);
...
}

这不允许我定义应用程序洞察的日志记录级别。 如何在 .net core 2.2.0 中定义日志记录级别?

最佳答案

请看一下这个article

如果是.net core web项目,可以使用以下代码在program.cs中设置日志级别:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging(
builder =>
{

builder.AddApplicationInsights("app insights instrumentation key");

// You can set log level here
builder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>
("", LogLevel.Information);
}
);

关于.net - 应用程序洞察 : loggerFactory. AddApplicationInsights 在 .net core 2.2.0 中已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55913933/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com