Skip to content

Commit

Permalink
Catch formatting exceptions in LoggerHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Jul 17, 2024
1 parent 9942a1e commit 59b2a63
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/xunit.runner.visualstudio/Utility/LoggerHelper.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -61,7 +62,14 @@ void SendMessage(
if (logger is null)
return;

var assemblyText = assemblyName is null ? "" : $"{Path.GetFileNameWithoutExtension(assemblyName)}: ";
logger.SendMessage(level, $"[xUnit.net {Stopwatch.Elapsed:hh\\:mm\\:ss\\.ff}] {assemblyText}{string.Format(CultureInfo.CurrentCulture, format, args)}");
try
{
var assemblyText = assemblyName is null ? "" : $"{Path.GetFileNameWithoutExtension(assemblyName)}: ";
logger.SendMessage(level, $"[xUnit.net {Stopwatch.Elapsed:hh\\:mm\\:ss\\.ff}] {assemblyText}{string.Format(CultureInfo.CurrentCulture, format, args)}");
}
catch (Exception ex)
{
logger.SendMessage(TestMessageLevel.Warning, $"Exception formatting {level} message '{format}': {ex}");
}
}
}

0 comments on commit 59b2a63

Please sign in to comment.