我已经将项目从 core 2.1更新到2.2,然后Program.cs中的logging.AddAzureWebAppDiagnostics()不再起作用.
I've updated my project from core 2.1 to 2.2 and then logging.AddAzureWebAppDiagnostics() in Program.cs no longer works.
public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .ConfigureLogging((hostingContext, logging) => { logging.AddAzureWebAppDiagnostics(); }) .UseStartup<Startup>() .Build(); }
'ILoggingBuilder'不包含'AddAzureWebAppDiagnostics'的定义,找不到可以接受的扩展方法'AddAzureWebAppDiagnostics'接受类型为'ILoggingBuilder'的第一个参数(您是否缺少using指令或程序集引用?
'ILoggingBuilder' does not contain a definition for 'AddAzureWebAppDiagnostics' and no accessible extension method 'AddAzureWebAppDiagnostics' accepting a first argument of type 'ILoggingBuilder' could be found (are you missing a using directive or an assembly reference?
请参考本文档,
如果定位.NET Framework或引用Microsoft.AspNetCore.App元包,则将提供程序包添加到项目中.在ILoggerFactory实例上调用AddAzureWebAppDiagnostics:
If targeting .NET Framework or referencing the Microsoft.AspNetCore.App metapackage, add the provider package to the project. Invoke AddAzureWebAppDiagnostics on an ILoggerFactory instance:
因此,方法可能与前一种方法略有不同.如何解决此问题?
So the way might be slightly different from the previous one. How do I fix this issue?
推荐答案文档有点棘手,但是如果仔细阅读,很明显应该采取以下步骤(对于 NET Core ):
The documentation is a bit tricky but if read carefully it become clear that following steps should be undertaken (for NET Core):
可以使用以下代码配置日志记录
Logging can be configired using following code // file startup.cs using Microsoft.Extensions.Logging.AzureAppServices; public class Startup { public void ConfigureServices(IServiceCollection services) { //... services.Configure<AzureFileLoggerOptions>(Configuration.GetSection("AzureLogging")); } }
文件appsettings.json应包含
"AzureLogging": { "FileName" : "azure-diagnostics-", "FileSizeLimit": 50024, "RetainedFileCountLimit": 5 }
应该在Azure门户上打开日志记录.启用后,Azure Portal可能会要求安装插件.需要安装插件的消息将显示在日志配置页面上.
Logging should be turned on on Azure Portal. After enabling, Azure Portal may ask for installing addon. Message requiring to install addon will appear on logging config page.
更多推荐
logging.AddAzureWebAppDiagnostics()在.net core 2.2中不起作用
发布评论