编程中添加和删除log4net的日志附加目的地 [英] Programmatically adding and removing log appenders in log4net

查看:204
本文介绍了编程中添加和删除log4net的日志附加目的地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用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 配置了<一href="http://logging.apache.org/log4net/release/sdk/log4net.Appender.MemoryAppender.html">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.

这篇关于编程中添加和删除log4net的日志附加目的地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆