Skip to content

Commit 8d290e0

Browse files
committed
Handle InvalidOperationException in XunitLogger to suppress logging errors during inactive tests.
1 parent 88133ad commit 8d290e0

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/common/Elsa.Testing.Shared/XunitLogger.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ public bool IsEnabled(LogLevel logLevel)
1212

1313
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
1414
{
15-
testOutputHelper.WriteLine($"{categoryName} [{eventId}] {formatter(state, exception)}");
15+
try
16+
{
17+
testOutputHelper.WriteLine($"{categoryName} [{eventId}] {formatter(state, exception)}");
1618

17-
if (exception != null)
18-
testOutputHelper.WriteLine(exception.ToString());
19+
if (exception != null)
20+
testOutputHelper.WriteLine(exception.ToString());
21+
}
22+
catch (InvalidOperationException)
23+
{
24+
// Suppress "no currently active test" exceptions that can occur when background tasks
25+
// (like timers) try to log after tests have completed
26+
}
1927
}
2028

2129
private class NoopDisposable : IDisposable

0 commit comments

Comments
 (0)