简体   繁体   English

ILotionBuilder在Appsettings中记录LogLevel在Azure日志流或Blob日志中似乎没有确认Json

[英]ILoggingBuilder Logging LogLevel in Appsettings Json doesn't seem to be acknowledged in Azure Log Stream or Blob Log

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. 我已经创建了一个新的.net核心2.1 Web应用程序并部署到Azure和Log Stream,而应用程序日志记录到Blob存储似乎并不尊重我的Logging配置。

I created a new Solution with a new project in Visual Studio 2019 for a .net core 2.1 web app. 我在Visual Studio 2019中为.net核心2.1 Web应用程序创建了一个新项目。 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();
}

And in the appsettings.Development.json we've set the LogLevel for System and Microsoft to "Error". appsettings.Development.json我们将System和Microsoft的LogLevel设置为“Error”。

What I expect is behavior in Azure to be what it is when ran locally. 我期望Azure中的行为与本地运行时的行为相同。 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: 在本地访问索引路由并使用appsettings.Development.json LogLevel for System和Microsoft设置为“Information”我们在Debug输出窗口中看到此输出:

Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http//localhost:44378/ Microsoft.AspNetCore.Hosting.Internal.WebHost:信息:请求启动HTTP / 1.1 GET http // localhost:44378 /
Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler:Information: Identity.Application was not authenticated. Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler:信息:Identity.Application未经过身份验证。 Failure message: Unprotect ticket failed Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Route matched with {action = "Index", controller = "Home", page = "", area = ""}. 失败消息:Unprotect票证失败Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:信息:路由与{action =“Index”,controller =“Home”,page =“”,area =“”}匹配。 Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult Index() on controller LoggingTest.Controllers.HomeController (LoggingTest). 在控制器LoggingTest.Controllers.HomeController(LoggingTest)上使用签名Microsoft.AspNetCore.Mvc.IActionResult Index()执行控制器操作。 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.Internal.ControllerActionInvoker:信息:执行操作方法LoggingTest.Controllers.HomeController.Index(LoggingTest) - 验证状态:有效LoggingTest.Controllers.HomeController:信息:============ ============================= LoggingTest.Controllers.HomeController:错误:============= ============================ Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:信息:执行的操作方法LoggingTest.Controllers.HomeController.Index (LoggingTest),返回结果Microsoft.AspNetCore.Mvc.ViewResult在7.9475ms。 Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:Information: Executing ViewResult, running view Index. Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:信息:执行ViewResult,运行视图索引。 Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:Information: Executed ViewResult - view Index executed in 11.4824ms. Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:信息:执行的ViewResult - 查看索引在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; 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 字符集= utf-8的

And when System and Microsoft are set to "Error": 当System和Microsoft设置为“Error”时:

LoggingTest.Controllers.HomeController:Information: ========================================= LoggingTest.Controllers.HomeController:Error: .========================================= LoggingTest.Controllers.HomeController:信息:========================================= LoggingTest .Controllers.HomeController:错误:。=========================================

We want this to be the case to be our output to our LogStream and Logs. 我们希望这是我们输出到LogStream和Logs的情况。 We essentially don't want the EfCore and other Microsoft related information in the log unless its of LogLevel "Error". 我们基本上不希望日志中包含EfCore和其他Microsoft相关信息,除非它的LogLevel为“Error”。 But we want our logs of Level "Information" to be logged. 但我们希望记录Level“Information”的日志。

After publishing to Azure and setting the ASPNETCORE_ENVIRONMENT to development to use the same Appsettings setup. 发布到Azure并将ASPNETCORE_ENVIRONMENT设置为开发以使用相同的Appsettings设置。 The log stream and blob for the log look like this after calling the index: 调用索引后,日志的日志流和blob如下所示:

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 = ""}. 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 =“”}。 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. 执行操作LoggingTest.Controllers.HomeController.Index(LoggingTest)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-05-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.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 [信息] Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:执行ViewResult,运行视图索引。 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 [信息] Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:执行的ViewResult - 查看在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; 2019-05-17 15:57:24.845 +00:00 [信息] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:执行动作LoggingTest.Controllers.HomeController.Index(LoggingTest)in 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 [Information] Microsoft.AspNetCore.Hosting.Internal.WebHost: Request starting HTTP/1.1 GET charset = utf-8 2019-05-17 15:57:24.941 +00:00 [信息] Microsoft.AspNetCore.Hosting.Internal.WebHost:请求启动HTTP / 1.1 GET

The rest of log removed for brevity... 删除其余日志以简洁起见......

Heres my appsettings.development.json file: 继承我的appsettings.development.json文件:

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

Heres my appsettings.json file: 继承我的appsettings.json文件:

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

Environement Variable set in Azure Web App: Azure Web App中设置的Environement变量:

ASPNETCORE_ENVIRONMENT = Development ASPNETCORE_ENVIRONMENT =开发

The Program.cs and Startup.cs are unmodified from the project template. Program.cs和Startup.cs未从项目模板中修改。

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? 为什么我的日志级别不被尊重?

In the past, I have used the following to configure the Azure log Provider 过去,我使用以下命令配置Azure日志提供程序

"AzureAppServicesDiagnosticsSettings": {
  "Microsoft": "Warning"
}

But reviewing the documentation that provider is now obsolete and is replaced with AzureFileLoggerOptions and AzureBlobLoggerOptions (see Logging in ASP.NET Core ). 但是,查看提供程序现已过时的文档 ,并替换为AzureFileLoggerOptions和AzureBlobLoggerOptions(请参阅登录ASP.NET Core )。

Though, I have not tested either of those configuration options to know if they work the same. 虽然,我没有测试过这些配置选项中的任何一个,以了解它们是否工作相同。

Finally able to make it work by placing these setting in my appsettings.development.json file: 最后能够通过将这些设置放在我的appsettings.development.json文件中来使其工作:

{
  "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"
      }
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM