Skip to content

Commit

Permalink
route logs to correct test output helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik Arvidsson committed Feb 4, 2022
1 parent e2428dc commit 3fa8059
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions tests/Kafka.TestFramework.Tests/TestSpecificationAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Kafka.TestFramework.Tests
{
public class TestSpecificationAsync : XUnit2SpecificationAsync
{
private readonly IDisposable _logWriter;

static TestSpecificationAsync()
{
var config = new ConfigurationBuilder()
Expand All @@ -21,26 +23,21 @@ static TestSpecificationAsync()

NLog.LogManager.Configuration = new NLogLoggingConfiguration(config.GetSection("NLog"));
LogFactory.Initialize(new NLogFactory(new LogicalThreadContext()));
NLogCapturingTarget.Subscribe += Output.Writer.WriteLine;
}

public TestSpecificationAsync(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
{
NLogCapturingTarget.Subscribe += TestOutputHelper.WriteLine;
_logWriter = Output.WriteTo(testOutputHelper);
}

protected CancellationToken TimeoutCancellationToken =>
new CancellationTokenSource(TimeSpan.FromSeconds(20)).Token;

protected virtual Task TearDownAsync()
{
return Task.CompletedTask;
}

protected sealed override async Task DisposeAsync(bool disposing)
{
NLogCapturingTarget.Subscribe -= TestOutputHelper.WriteLine;
await TearDownAsync();
await base.DisposeAsync(disposing);
_logWriter.Dispose();
}
}
}

0 comments on commit 3fa8059

Please sign in to comment.