6

We have some code that emits messages to log4net and would like to see those same messages emitted when we run tests on that code under xUnit.

Is there a way to tell xUnit to start up log4net? I have modified the .config file for xunit.console It runs fine, but there is no indication of any logging activity.

1 Answer 1

0

Generally when unit testing log4net log calls, a 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()); 
}
1
  • 3
    This code would allow to test if log entries are produced, however if I understand OP correctly he just wants to see the output in console window. Oct 6, 2014 at 5:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.