我正在使用Microsoft.Extensions.Logging
。
如果我有:
private readonly ILogger<App> _log;
_log.LogTrace(SomeHeavySerialization(someHeavyObject));
如果所选的日志记录级别大于&#34; trace&#34;?
,如何避免执行SomeHeavySerialization(someHeavyObject)
例如:
var logLevel = _log.GetLogLevel_ThisFunctionDoesNotReallyExist();
if(logLevel <= theOneThatIWant)
_log.LogTrace(SomeHeavySerialization(someHeavyObject));