AppSettings中的ILoggingBuilder日志记录LogLevel似乎在Azure Log Stream或Blob Log中未确认Json [英] ILoggingBuilder Logging LogLevel in Appsettings Json doesn't seem to be acknowledged in Azure Log Stream or Blob Log

查看:776
本文介绍了AppSettings中的ILoggingBuilder日志记录LogLevel似乎在Azure Log Stream或Blob Log中未确认Json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个新的.net core 2.1 Web应用程序,并已部署到Azure和Log Stream,并且应用程序日志记录到Blob"存储似乎不符合我的日志记录配置.

I've created a new .net core 2.1 web app and deployed to Azure and Log Stream and and Application Logging to Blob storage don't seem to be honoring my Logging configuration.

我在Visual Studio 2019中为.net core 2.1 Web应用程序创建了一个带有新项目的新解决方案.在家庭控制器的Index路由中,我们在行日志中添加了一些类似于以下内容的信息:

I created a new Solution with a new project in Visual Studio 2019 for a .net core 2.1 web app. In the home controller Index route, we added a line log some information that looks like this:

private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger)
{
    _logger = logger;
}

public IActionResult Index()
{
    _logger.LogInformation("=========================================");
    _logger.LogError("=========================================");
    return View();
}

appsettings.Development.json中,我们已将System和Microsoft的LogLevel设置为错误".

And in the appsettings.Development.json we've set the LogLevel for System and Microsoft to "Error".

我期望Azure在本地运行时的行为.在本地访问索引路由并把appsettings.Development.json系统和Mi​​crosoft的LogLevel设置为信息"时,我们会在调试输出"窗口中看到以下输出:

What I expect is behavior in Azure to be what it is when ran locally. Locally when accessing the index route and having the appsettings.Development.json LogLevel for System and Microsoft set to "Information" We see this output in the Debug output window:

Microsoft.AspNetCore.Hosting.Internal.WebHost:信息:请求 开始HTTP/1.1 GET http//localhost:44378/
Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler:信息: Identity.Application未通过身份验证.失败消息:取消保护 票务失败 Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:信息: 与{action ="Index",controller ="Home",page ="匹配的路由, area ="}.执行带有签名的控制器动作 控制器上的Microsoft.AspNetCore.Mvc.IActionResult Index() LoggingTest.Controllers.HomeController(LoggingTest). Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:信息: 执行动作方法LoggingTest.Controllers.HomeController.Index (LoggingTest)-验证状态:有效 LoggingTest.Controllers.HomeController:信息: ========================================================================================================================================================================================================================================================================================================== = ========================================= Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker :信息: 执行的操作方法LoggingTest.Controllers.HomeController.Index (LoggingTest),返回结果Microsoft.AspNetCore.Mvc.ViewResult在 7.9475毫秒. Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:信息: 执行ViewResult,运行视图索引. Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:信息: 已执行ViewResult-在11.4824毫秒内执行的视图索引. Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:信息: 执行的操作LoggingTest.Controllers.HomeController.Index (LoggingTest)在37.629ms Microsoft.AspNetCore.Hosting.Internal.WebHost:信息:请求 完成于54.1369ms 200 text/html; charset = utf-8

Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http//localhost:44378/
Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler:Information: Identity.Application was not authenticated. Failure message: Unprotect ticket failed Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Route matched with {action = "Index", controller = "Home", page = "", area = ""}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult Index() on controller LoggingTest.Controllers.HomeController (LoggingTest). Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executing action method LoggingTest.Controllers.HomeController.Index (LoggingTest) - Validation state: Valid LoggingTest.Controllers.HomeController:Information: ========================================= LoggingTest.Controllers.HomeController:Error: ========================================= Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed action method LoggingTest.Controllers.HomeController.Index (LoggingTest), returned result Microsoft.AspNetCore.Mvc.ViewResult in 7.9475ms. Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:Information: Executing ViewResult, running view Index. Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:Information: Executed ViewResult - view Index executed in 11.4824ms. Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed action LoggingTest.Controllers.HomeController.Index (LoggingTest) in 37.629ms Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 54.1369ms 200 text/html; charset=utf-8

并且当System和Microsoft设置为错误"时:

And when System and Microsoft are set to "Error":

LoggingTest.Controllers.HomeController:信息: ========================================================================================================================================================================================================================================================================================================== = .=======================================

LoggingTest.Controllers.HomeController:Information: ========================================= LoggingTest.Controllers.HomeController:Error: .=========================================

我们希望这种情况成为我们向LogStream和Logs的输出.除非LogLevel为错误",否则我们基本上不希望EfCore和其他Microsoft相关信息出现在日志中.但是我们希望记录信息"级别的日志.

We want this to be the case to be our output to our LogStream and Logs. We essentially don't want the EfCore and other Microsoft related information in the log unless its of LogLevel "Error". But we want our logs of Level "Information" to be logged.

发布到Azure并将ASPNETCORE_ENVIRONMENT设置为开发后,可以使用相同的Appsettings设置.调用索引后,日志流和日志的blob如下所示:

After publishing to Azure and setting the ASPNETCORE_ENVIRONMENT to development to use the same Appsettings setup. The log stream and blob for the log look like this after calling the index:

2019-05-17 15:57:24.844 +00:00 [信息] Microsoft.AspNetCore.Hosting.Internal.WebHost:请求启动 HTTP/1.1 GET http//loggingtest20190517104201.azurewebsites.net/ 2019-05-17 15:57:24.844 +00:00 [信息] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:路由 与{action ="Index",controller ="Home",page =",area =匹配 "}.执行动作LoggingTest.Controllers.HomeController.Index (记录测试)2019-05-17 15:57:24.844 +00:00 [信息] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:执行 动作方法LoggingTest.Controllers.HomeController.Index (LoggingTest)-验证状态:有效2019-05-17 15:57:24.844 +00:00 [信息] LoggingTest.Controllers.HomeController: ========================================== 2019年5月17日15:57: 24.845 +00:00 [错误] LoggingTest.Controllers.HomeController:=================================== ===== 2019-05-17 15:57:24.845 +00:00 [信息] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:已执行 动作方法LoggingTest.Controllers.HomeController.Index (LoggingTest),返回结果Microsoft.AspNetCore.Mvc.ViewResult在 0.0635毫秒. 2019-05-17 15:57:24.845 +00:00 [Information] Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:执行中 ViewResult,运行视图索引. 2019-05-17 15:57:24.845 +00:00 [信息] Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:已执行 ViewResult-视图索引在0.8902毫秒内执行. 2019-05-17 15:57:24.845 +00:00 [信息] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:已执行 在以下位置执行LoggingTest.Controllers.HomeController.Index(LoggingTest)操作 1.0913ms 2019-05-17 15:57:24.846 +00:00 [信息] Microsoft.AspNetCore.Hosting.Internal.WebHost:请求已完成 1.4542ms 200文本/html; charset = utf-8 2019-05-17 15:57:24.941 +00:00 [信息] Microsoft.AspNetCore.Hosting.Internal.WebHost:请求 开始HTTP/1.1 GET

2019-05-17 15:57:24.844 +00:00 [Information] Microsoft.AspNetCore.Hosting.Internal.WebHost: Request starting HTTP/1.1 GET http//loggingtest20190517104201.azurewebsites.net/ 2019-05-17 15:57:24.844 +00:00 [Information] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker: Route matched with {action = "Index", controller = "Home", page = "", area = ""}. Executing action LoggingTest.Controllers.HomeController.Index (LoggingTest) 2019-05-17 15:57:24.844 +00:00 [Information] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker: Executing action method LoggingTest.Controllers.HomeController.Index (LoggingTest) - Validation state: Valid 2019-05-17 15:57:24.844 +00:00 [Information] LoggingTest.Controllers.HomeController: ========================================= 2019-05-17 15:57:24.845 +00:00 [Error] LoggingTest.Controllers.HomeController: ========================================= 2019-05-17 15:57:24.845 +00:00 [Information] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker: Executed action method LoggingTest.Controllers.HomeController.Index (LoggingTest), returned result Microsoft.AspNetCore.Mvc.ViewResult in 0.0635ms. 2019-05-17 15:57:24.845 +00:00 [Information] Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor: Executing ViewResult, running view Index. 2019-05-17 15:57:24.845 +00:00 [Information] Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor: Executed ViewResult - view Index executed in 0.8902ms. 2019-05-17 15:57:24.845 +00:00 [Information] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker: Executed action LoggingTest.Controllers.HomeController.Index (LoggingTest) in 1.0913ms 2019-05-17 15:57:24.846 +00:00 [Information] Microsoft.AspNetCore.Hosting.Internal.WebHost: Request finished in 1.4542ms 200 text/html; charset=utf-8 2019-05-17 15:57:24.941 +00:00 [Information] Microsoft.AspNetCore.Hosting.Internal.WebHost: Request starting HTTP/1.1 GET

为简便起见,删除了其余日志...

The rest of log removed for brevity...

这里有我的appsettings.development.json文件:

Heres my appsettings.development.json file:

{
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Error",
      "Microsoft": "Error"
    }
  }
}

这里有我的appsettings.json文件:

Heres my appsettings.json file:

{
  "ConnectionStrings": {
    "DefaultConnection": "Removed"
  }, 
  "AllowedHosts": "*"
}

在Azure Web App中设置的环境变量:

Environement Variable set in Azure Web App:

ASPNETCORE_ENVIRONMENT =开发

从项目模板中未修改Program.cs和Startup.cs.

The Program.cs and Startup.cs are unmodified from the project template.

public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

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

为什么不遵守我的日志级别?

Why are my Log Levels not being honored?

推荐答案

最后可以通过将这些设置放在我的appsettings.development.json文件中使其工作:

Finally able to make it work by placing these setting in my appsettings.development.json file:

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Information",
      "System": "Error",
      "Microsoft": "Error"
    },
    "AzureAppServicesBlob": {
      "LogLevel": {
        "Default": "Information",
        "Microsoft": "Error",
        "System": "Error"
      }
    },
    "AzureAppServicesFile": {
      "LogLevel": {
        "Default": "Information",
        "Microsoft": "Error",
        "System": "Error"
      }
    }
  }
}

这篇关于AppSettings中的ILoggingBuilder日志记录LogLevel似乎在Azure Log Stream或Blob Log中未确认Json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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