From b02d613a28bcedc0ac53eb8b990ef4ed35ed41e5 Mon Sep 17 00:00:00 2001 From: John Gross Date: Tue, 5 Nov 2019 10:19:16 -0800 Subject: [PATCH] Fix crash when logging pre-formatted messages --- Torch/Managers/KeenLogPatch.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Torch/Managers/KeenLogPatch.cs b/Torch/Managers/KeenLogPatch.cs index ce9d8a9..08e70c8 100644 --- a/Torch/Managers/KeenLogPatch.cs +++ b/Torch/Managers/KeenLogPatch.cs @@ -131,7 +131,15 @@ namespace Torch.Managers private static bool PrefixLogFormatted(MyLog __instance, MyLogSeverity severity, string format, object[] args) { - _log.Log(LogLevelFor(severity), PrepareLog(__instance).AppendFormat(format, args)); + // Sometimes this is called with a pre-formatted string and no args + // and causes a crash when the format string contains braces + var sb = PrepareLog(__instance); + if (args != null && args.Length > 0) + sb.AppendFormat(format, args); + else + sb.Append(format); + + _log.Log(LogLevelFor(severity), sb); return false; }