logging.AddAzureWebAppDiagnostics()在.net core 2.2中不起作用 [英] logging.AddAzureWebAppDiagnostics() does not work in .net core 2.2

查看:147
本文介绍了logging.AddAzureWebAppDiagnostics()在.net core 2.2中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将项目从.net core 2.1更新到2.2,然后Program.cs中的logging.AddAzureWebAppDiagnostics()不再起作用.

I've updated my project from .net 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?

推荐答案

The documentation is a bit tricky but if read carefully it become clear that following steps should be undertaken (for NET Core):

  1. Microsoft.Extensions.Logging.AzureAppServices应该已安装
  2. 无需致电logging.AddAzureWebAppDiagnostics();
  3. 可以使用以下代码配置日志记录

  1. Microsoft.Extensions.Logging.AzureAppServices should be installed
  2. There is NO need to call logging.AddAzureWebAppDiagnostics();
  3. 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.

    1. 在代码中调用logger.LogWarning ("message");以写入日志文件.如果您使用LogWarning,请确保将级别"设置为警告"或更详细(信息或调试)
    1. Call logger.LogWarning ("message"); in your code to write to log file. If you use LogWarning be sure to set Level to Warning or more detailed (Info or Debug)

    这篇关于logging.AddAzureWebAppDiagnostics()在.net core 2.2中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆