TDDing Log4net
time to read 1 min | 146 words
I have an application where logging is a business concern.
Usually, logging is something that I do so I could remotely debug the application, or have a better understanding of what is going on. This is the first time where the logs are actually something that is a business concern.
I usually don't tests logging, so I wasn't sure how to start. I probably should mention that I am using log4net for the logs.
After searching a bit, I found that it is really simple:
And then, in the tests, all you need to do is:
Strangely, the best place to read about log4net strengths is here, in the comments for a blog post (check the second comment by Ron Grabowski).
Usually, logging is something that I do so I could remotely debug the application, or have a better understanding of what is going on. This is the first time where the logs are actually something that is a business concern.
I usually don't tests logging, so I wasn't sure how to start. I probably should mention that I am using log4net for the logs.
After searching a bit, I found that it is really simple:
[SetUp]
public void TestInitialize()
{
_memoryAppender = new MemoryAppender();
BasicConfigurator.Configure(_memoryAppender);
}
And then, in the tests, all you need to do is:
LoggingEvent[] events = _memoryApender.GetEvents();And start asserting.
Strangely, the best place to read about log4net strengths is here, in the comments for a blog post (check the second comment by Ron Grabowski).
Comments
Comment preview