Last active
November 25, 2015 16:52
-
-
Save timiles/5c7a31af2e43d480df65 to your computer and use it in GitHub Desktop.
log4net appender for xunit output. credit: http://stackoverflow.com/a/29907379/487544
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using log4net.Appender; | |
using log4net.Core; | |
using log4net.Layout; | |
using Xunit.Abstractions; | |
public class TestOutputAppender : AppenderSkeleton | |
{ | |
private readonly ITestOutputHelper _xunitTestOutputHelper; | |
public TestOutputAppender(ITestOutputHelper xunitTestOutputHelper) | |
{ | |
this._xunitTestOutputHelper = xunitTestOutputHelper; | |
this.Name = "TestOutputAppender"; | |
this.Layout = new PatternLayout("%date [%thread] %-5level %logger - %message"); | |
} | |
protected override void Append(LoggingEvent loggingEvent) | |
{ | |
this._xunitTestOutputHelper.WriteLine(this.RenderLoggingEvent(loggingEvent)); | |
} | |
} | |
/* | |
// Wire up in test class's constructor: | |
public MyTestClass(ITestOutputHelper output) | |
{ | |
BasicConfigurator.Configure(new TestOutputAppender(output)); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment