From 3108735d0fb8bf8345ac0e9277a0a60ff145295b Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 26 Mar 2020 09:34:51 -0700 Subject: [PATCH] Fixed issues when JSON is logged (#210) --- .../DiagnosticsCollector.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.Tye.Hosting.Diagnostics/DiagnosticsCollector.cs b/src/Microsoft.Tye.Hosting.Diagnostics/DiagnosticsCollector.cs index 884dce81..65790b29 100644 --- a/src/Microsoft.Tye.Hosting.Diagnostics/DiagnosticsCollector.cs +++ b/src/Microsoft.Tye.Hosting.Diagnostics/DiagnosticsCollector.cs @@ -375,7 +375,17 @@ namespace Microsoft.Tye.Hosting.Diagnostics var args = new object[formatter.ValueNames.Count]; for (var i = 0; i < args.Length; i++) { - args[i] = message.GetProperty(formatter.ValueNames[i]).GetString(); + if (!message.TryGetProperty(formatter.ValueNames[i], out var argValue)) + { + // We couldn't find the parsed property in the original message, it's likely that this is a JSON object or something else + // being logged, or some other format that just looks like the formatted message. Stop here and log the formatted message + var obj = new LogObject(message, lastFormattedMessage); + logger.Log(logLevel, new EventId(eventId, eventName), obj, exception, LogObject.Callback); + + break; + } + + args[i] = argValue.GetString(); } logger.Log(logLevel, new EventId(eventId, eventName), exception, formatString, args);