编程中添加和删除log4net的日志附加目的地目的地、日志、log4net

由网友(金钱美酒凯子与狗)分享简介:我有一个使用log4net的一个组成部分。我想创建单元测试,也验证了某些错误情况导致了正确的记录。I have a component that uses log4net. I want to create unit tests, that validate that certain error conditions...

我有一个使用log4net的一个组成部分。我想创建单元测试,也验证了某些错误情况导致了正确的记录。

I have a component that uses log4net. I want to create unit tests, that validate that certain error conditions result in the correct logging.

我在想,要做到这一点的最好办法是创建一个ILogAppender实现,例如模拟。然后我会在日志附加目的地添加到log4net的测试设置中,检查什么在测试验证是书面的,而在测试拆卸再次将其删除。

I was thinking that the best way to do this is to create an ILogAppender implementation, for example a mock. I would then add the log appender to log4net during test setup, inspect what was written during test validation, and remove it again during test teardown.

这可能吗?

推荐答案

我一直使用的BasicConfigurator 配置了MemoryAppender.该附加器让你能在内存中的信息在测试过程中记录的。

I have been using the BasicConfigurator configured with a MemoryAppender. This appender lets you get to the in-memory messages logged during your test.

阅读全文

相关推荐

最新文章