简体   繁体   English

使用log4net和xUnit

[英]Using log4net and xUnit

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. 我们有一些代码向log4net发送消息,并希望在xUnit下对该代码运行测试时看到相同的消息。

Is there a way to tell xUnit to start up log4net? 有没有办法告诉xUnit启动log4net? I have modified the .config file for xunit.console It runs fine, but there is no indication of any logging activity. 我修改了xunit.console的.config文件它运行正常,但没有任何记录活动的迹象。

Generally when unit testing log4net log calls, a MemoryAppender is used like this: 通常在单元测试log4net日志调用时,使用MemoryAppender如下:

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()); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM