From 11144e70ead337252e3dc7f0c49291ebee4343e9 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Wed, 9 Feb 2022 13:04:55 +0100 Subject: [PATCH] Partial revert of #1803 since Azure.Cosmos still uses newtonsoft (#1843) --- src/Admin/Models/LogModel.cs | 44 ++++++++++++++---------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/src/Admin/Models/LogModel.cs b/src/Admin/Models/LogModel.cs index 6675c81ee..16f90b5df 100644 --- a/src/Admin/Models/LogModel.cs +++ b/src/Admin/Models/LogModel.cs @@ -1,8 +1,6 @@ using System.Collections.Generic; -using System.Text; -using System.Text.Json; -using Bit.Core.Utilities; using Microsoft.Azure.Documents; +using Newtonsoft.Json.Linq; namespace Bit.Admin.Models { @@ -19,48 +17,40 @@ namespace Bit.Admin.Models public class LogDetailsModel : LogModel { - public JsonDocument Exception { get; set; } + public JObject Exception { get; set; } - public string ExceptionToString(JsonDocument e) + public string ExceptionToString(JObject e) { if (e == null) { return null; } - var root = e.RootElement; - - var sb = new StringBuilder(); - if (root.TryGetProperty("Message", out var messageProp) && messageProp.GetString() != null) + var val = string.Empty; + if (e["Message"] != null && e["Message"].ToObject() != null) { - sb.AppendLine("Message:"); - sb.AppendLine(messageProp.GetString()); + val += "Message:\n"; + val += e["Message"] + "\n"; } - if (root.TryGetProperty("StackTrace", out var stackTraceProp) && stackTraceProp.GetString() != null) + if (e["StackTrace"] != null && e["StackTrace"].ToObject() != null) { - sb.AppendLine(); - sb.AppendLine("Stack Trace:"); - sb.Append(stackTraceProp.GetString()); + val += "\nStack Trace:\n"; + val += e["StackTrace"]; } - else if (root.TryGetProperty("StackTraceString", out var stackTraceStringProp) && stackTraceStringProp.GetString() != null) + else if (e["StackTraceString"] != null && e["StackTraceString"].ToObject() != null) { - sb.AppendLine(); - sb.AppendLine("Stack Trace String:"); - sb.Append(stackTraceStringProp.GetString()); + val += "\nStack Trace String:\n"; + val += e["StackTraceString"]; } - if (root.TryGetProperty("InnerException", out var innerExceptionProp) && innerExceptionProp.ValueKind == JsonValueKind.Object) + if (e["InnerException"] != null && e["InnerException"].ToObject() != null) { - sb.AppendLine(); - sb.AppendLine(); - sb.AppendLine("=== Inner Exception ==="); - sb.AppendLine(); - sb.AppendLine(ExceptionToString(innerExceptionProp.ToObject())); - sb.AppendLine(); + val += "\n\n=== Inner Exception ===\n\n"; + val += ExceptionToString(e["InnerException"].ToObject()); } - return sb.ToString(); + return val; } } }