asp.net - ASP.NET Core 中的默认日志级别、系统日志级别和 Microsoft 日志级别是什么

标签 asp.net logging asp.net-core asp.net-core-mvc

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

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

DefaultSystemMicrosoft 有何用途?

最佳答案

SystemMicrosoft 命名空间程序集都具有受尊重的日志记录级别。考虑一个 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 方法记录异常,则不会将其写入日志输出。

关于asp.net - ASP.NET Core 中的默认日志级别、系统日志级别和 Microsoft 日志级别是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37417660/

相关文章:

docker - Docker-ASP.CORE 2.2应用程序和SSH

asp.net - 按钮悬停着色

使用 Azure Log Analytics 进行 Python 应用程序日志记录

javascript - 在 IE 中写入脚本控制台 (console.log) 的正确方法是什么?

logging - JHipster - 日志文件

c# - EF代码首先不创建数据库

c# - 如何在 Asp Net Core RC1 MVC 中使用 token 身份验证添加 "ApiController"

asp.net - 如何在 ASP.net 的 gridView 中设置每页的最大页面大小

c# - 在成员(member)中启用密码重置

C#、ASP.NET - NullReferenceException - 对象引用未设置为对象的实例