If you're using Moq >= 4.13, here is a way to mock ILogger
:
logger.Verify(x => x.Log(
It.IsAny<LogLevel>(),
It.IsAny<EventId>(),
It.IsAny<It.IsAnyType>(),
It.IsAny<Exception>(),
(Func<It.IsAnyType, Exception, string>)It.IsAny<object>()));
You can change the It.IsAny<LogLevel>()
, It.IsAny<EventId>()
, and It.IsAny<Exception>()
stubs to be more specific, but using It.IsAnyType
is necessary because FormattedLogValues
is now internal
.
Reference: TState in ILogger.Log used to be object, now FormattedLogValues
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…