Asp.net

ASP.NET Core 中的 Default、System 和 Microsoft LogLevel 是什麼

  • July 25, 2019

預設項目模板在 中具有以下日誌記錄配置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”為前綴。在內部,它的日誌記錄將以您的配置中指定的級別輸出。

同樣,在您的應用程序"Default"中與您的應用程序相關。考慮以下:

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,它不會被寫入到日誌的輸出中。

引用自:https://stackoverflow.com/questions/37417660