Skip to content

Commit

Permalink
[CI] Account for InvalidOperationException in XunitLogger (#5940)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkl committed Jul 31, 2024
1 parent 29c64d4 commit b303698
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/TestUtilities/Test.Utility/XunitLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ public override void Log(ILogMessage message)
var level = message.Level.ToString().ToLowerInvariant();
level = level.Substring(0, Math.Min(level.Length, 4));

Output.WriteLine($"[test] {level}: {message.Message}");
try
{
Output.WriteLine($"[test] {level}: {message.Message}");
}
catch (InvalidOperationException)
{
// Under some circumstances, the output helper may throw an System.InvalidOperationException : There is no currently active test so fall back to writing to the console instead of failing the test.
Console.WriteLine($"[test] {level}: {message.Message}");
}
}

public override Task LogAsync(ILogMessage message)
Expand Down

0 comments on commit b303698

Please sign in to comment.