【发布时间】:2019-07-22 16:00:23
【问题描述】:
我已将我的项目从 .net core 2.1 更新到 2.2,然后 Program.cs 中的 logging.AddAzureWebAppDiagnostics() 不再工作。
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddAzureWebAppDiagnostics();
})
.UseStartup<Startup>()
.Build();
}
“ILoggingBuilder”不包含“AddAzureWebAppDiagnostics”的定义,并且找不到接受“ILoggingBuilder”类型的第一个参数的可访问扩展方法“AddAzureWebAppDiagnostics”(您是否缺少 using 指令或程序集引用?
如果面向 .NET Framework 或引用 Microsoft.AspNetCore.App 元包,请将提供程序包添加到项目中。在 ILoggerFactory 实例上调用 AddAzureWebAppDiagnostics:
所以方式可能与前一种方式略有不同。我该如何解决这个问题?
【问题讨论】:
-
可能是个愚蠢的问题.. 你添加了
using Microsoft.Extensions.Logging;声明吗? -
是的,我有声明。它适用于 .net 2.0 和 2.1。
-
也在链接文档中提到,
If targeting .NET Core, note the following points: Don't explicitly call AddAzureWebAppDiagnostics. -
我也用
Microsoft.AspNetCore.App,这就是为什么我提到了文档中的声明。 -
谈论在 ILoggerFactory 实例上调用 AddAzureWebAppDiagnostics。这里有 ILoggingBuilder。如您所见here,该方法设置为已过时并带有注释
will be removed in a future version.The alternative is AddAzureWebAppDiagnostics(this ILoggingBuilder builder)
标签: c# asp.net-core asp.net-core-2.2