我试图了解ILogger 接口中IsEnabled方法的目的。我希望每次可以记录某些内容时都会自动调用该方法,但是无论返回 IsEnabled 什么,都会调用方法 Log。
我应该在 Log 方法中检查 IsEnabled 吗?
public bool IsEnabled(LogLevel logLevel)
{
return logLevel >= this.level;
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
if (this.IsEnabled(logLevel)) //it seams that this is required ????
{
string s = formatter(state, exception);
string formatted = s.Replace("\r\n", "\r\n ");
Console.WriteLine(string.Format("{0,-15} {1,-5} - {2}", logLevel, eventId, formatted));
}
}
Run Code Online (Sandbox Code Playgroud)
那么目的是什么以及谁(为什么)调用 IsEnabled。
asp.net-core ×1