默认项目模板在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方法记录异常,则不会将其写入日志的输出中.