Skip to content

Instantly share code, notes, and snippets.

@timiles
Last active November 25, 2015 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timiles/5c7a31af2e43d480df65 to your computer and use it in GitHub Desktop.
Save timiles/5c7a31af2e43d480df65 to your computer and use it in GitHub Desktop.
log4net appender for xunit output. credit: http://stackoverflow.com/a/29907379/487544
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