logging.AddAzureWebAppDiagnostics()在.net core 2.2中不起作用

编程入门 行业动态 更新时间:2024-10-27 06:26:18
本文介绍了logging.AddAzureWebAppDiagnostics()在 core 2.2中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经将项目从 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):

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

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

  • 在代码中调用logger.LogWarning ("message");以写入日志文件.如果您使用LogWarning,请确保将级别"设置为警告"或更详细(信息或调试)
  • 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中不起作用

    本文发布于:2023-11-15 07:05:23,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1592221.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:中不   AddAzureWebAppDiagnostics   logging   net   core

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!