diff --git a/Framework/Tracing/TraceHelper.cs b/Framework/Tracing/TraceHelper.cs index 33fccf2be..8f73951db 100644 --- a/Framework/Tracing/TraceHelper.cs +++ b/Framework/Tracing/TraceHelper.cs @@ -190,7 +190,23 @@ static string GetFormattedString(string iid, string eid, string message, params { formatted = "msg=" + message; } - return string.Format(formatted, args); + + if (args == null) + { + return formatted; + } + + try + { + return string.Format(formatted, args); + } + catch (FormatException ex) + { + source.TraceEvent(TraceEventType.Error, 0, + "String FormatException for '{0}'. Args count: {1}. Exception: {2}", formatted, args.Length, ex); + + return formatted; + } } static void ExceptionHandlingWrapper(Action innerFunc) @@ -207,7 +223,7 @@ static void ExceptionHandlingWrapper(Action innerFunc) } try { - source.TraceEvent(TraceEventType.Critical, 0, + source.TraceEvent(TraceEventType.Error, 0, $"Failed to log actual trace because one or more trace listeners threw an exception: {exception}"); } catch (Exception anotherException)