Using log4net and xUnit
We have a code that posts messages to log4net and would like to see the same messages that were issued when we run tests of this code in xUnit.
Is there a way to tell xUnit to run log4net? I have changed the .config file for xunit.console. It is working fine, but there is no sign of registration activity.
+3
source to share
1 answer
Typically when log4net unit testing is logarithm, MemoryAppender is used like this:
private MemoryAppender testAppender;
[SetUp]
public void SetUp()
{
testAppender = new MemoryAppender();
BasicConfigurator.Configure(testAppender);
// etc
}
[Test]
public void TestLogging()
{
// etc
var events = testAppender().GetEvents();
Assert.AreEqual(1, events.Count());
}
0
source to share