没有。 ILogger 是一个接口。它什么也没做。相反,ILogger 的实现应该记录未捕获的异常。听起来 Rollbar 已经在记录您的日志,因此您应该继续使用它来记录未捕获的异常,或者切换到 NLog、Serilog 或 log4net 等其他库。
就个人而言,我发现某些库在不同情况下确实会丢失消息,因此测试您的日志库很重要。仅仅相信消息被正确写入是不够的。您可以编写单元测试以确保您的代码使用 Moq 正确记录异常。这是来自this article 的示例。
_loggerMock.Verify
(
l => l.Log
(
//Check the severity level
LogLevel.Error,
//This may or may not be relevant to your scenario
It.IsAny<EventId>(),
//This is the magical Moq code that exposes internal log processing from the extension methods
It.Is<It.IsAnyType>((state, t) =>
//This confirms that the correct log message was sent to the logger. {OriginalFormat} should match the value passed to the logger
//Note: messages should be retrieved from a service that will probably store the strings in a resource file
CheckValue(state, LogTest.ErrorMessage, "{OriginalFormat}") &&
//This confirms that an argument with a key of "recordId" was sent with the correct value
//In Application Insights, this will turn up in Custom Dimensions
CheckValue(state, recordId, nameof(recordId))
),
//Confirm the exception type
It.IsAny<NotImplementedException>(),
//Accept any valid Func here. The Func is specified by the extension methods
(Func<It.IsAnyType, Exception, string>)It.IsAny<object>()),
//Make sure the message was logged the correct number of times
Times.Exactly(1)
);
但是,即使这样也不能保证 Rollbar 或其他记录器一定会将您的消息发送到日志位置。您只能通过观察记录器的输出来确认这一点。
您还应该查看ILogger 文档中的this section,其中解释了如何配置日志记录并可能过滤它们。