默认项目模板在 appSettings.json
中具有以下日志记录配置:
"Logging": {
"IncludeScopes": true,
"LogLevel":
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
Default
、System
和 Microsoft
有何用途?
最佳答案
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
方法记录异常,则不会将其写入日志输出。
关于asp.net - ASP.NET Core 中的默认日志级别、系统日志级别和 Microsoft 日志级别是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37417660/