ASP.NET Core MVC 6中的默认,系统和Mi​​crosoft LogLevels是什么

认项目模板在appSettings.json中具有以下日志记录配置:

"Logging": {
  "IncludeScopes": true,"LogLevel": 
    "Default": "Debug","System": "information","Microsoft": "information"
  }
}

什么是认,系统和微软?

解决方法

System和Microsoft命名空间程序集都具有值得尊重的日志记录级别.考虑一个MVC 6应用程序,想象一下你的project.json你有一个依赖“Microsoft.AspNetCore.Mvc”:“1.0.0-rc2-final” – 这个程序集以“Microsoft”为前缀.在内部,它的日志记录将以您的配置中指定的级别输出.

同样,在您的应用程序中,“认”与您的应用程序相关.考虑以下:

void FooBar(ILogger logger)
{
    logger.LogCritical("LoglLevel.Critical");
    logger.LogDebug("LoglLevel.Debug");
    logger.LogError("LoglLevel.Errror");
    logger.Loginformation("LoglLevel.information");
    logger.LogTrace("LoglLevel.Trace"); // This message would not be written
    logger.LogWarning("LoglLevel.Warning");
}

// This is the severity
public enum LogLevel
{
    Trace,Debug,information,Warning,Error,Critical,None
}

因此,如果您设置“Microsoft”:“Critical”并且内部MVC遇到并通过logger.LogError方法记录异常,则不会将其写入日志的输出中.

相关文章

本文将从上往下,循序渐进的介绍一系列相关.NET的概念,先从...
基于 .NET 的一个全新的、好用的 PHP SDK + Runtime: Pe...
.NET 异步工作原理介绍。
引子 .NET 6 开始初步引入 PGO。PGO 即 Profile Guided Opti...
前言 2021/4/8 .NET 6 Preview 3 发布,这个版本的改进大多来...
前言 开头防杠:.NET 的基础库、语言、运行时团队从来都是相...