Fix crash when logging pre-formatted messages

This commit is contained in:
John Gross
2019-11-05 10:19:16 -08:00
parent cc91fa3653
commit b02d613a28

View File

@@ -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;
}