From c63422ea5d37b4c9d62225af03407c1bcaa4866a Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 30 Mar 2018 17:35:07 -0400 Subject: [PATCH] log exception strings --- src/Admin/Controllers/LogsController.cs | 2 +- src/Admin/Models/LogModel.cs | 49 +++++++++++++++++++------ src/Admin/Views/Logs/View.cshtml | 4 +- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/Admin/Controllers/LogsController.cs b/src/Admin/Controllers/LogsController.cs index 3ec71b0f1..db1f7efc7 100644 --- a/src/Admin/Controllers/LogsController.cs +++ b/src/Admin/Controllers/LogsController.cs @@ -70,7 +70,7 @@ namespace Bit.Admin.Controllers _globalSettings.DocumentDb.Key)) { var uri = UriFactory.CreateDocumentUri(Database, Collection, id.ToString()); - var response = await client.ReadDocumentAsync(uri); + var response = await client.ReadDocumentAsync(uri); if(response?.Document == null) { return RedirectToAction("Index"); diff --git a/src/Admin/Models/LogModel.cs b/src/Admin/Models/LogModel.cs index aec7908da..1fb1a1987 100644 --- a/src/Admin/Models/LogModel.cs +++ b/src/Admin/Models/LogModel.cs @@ -1,9 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; +using System.Collections.Generic; using Microsoft.Azure.Documents; -using Newtonsoft.Json; -using Serilog.Events; +using Newtonsoft.Json.Linq; namespace Bit.Admin.Models { @@ -14,18 +11,46 @@ namespace Bit.Admin.Models public string Message { get; set; } public string MessageTruncated => Message.Length > 200 ? $"{Message.Substring(0, 200)}..." : Message; public string MessageTemplate { get; set; } - public Error Exception { get; set; } public IDictionary Properties { get; set; } public string Project => Properties?.ContainsKey("Project") ?? false ? Properties["Project"].ToString() : null; + } - [JsonObject(MemberSerialization.OptIn)] - public class Error : Exception, ISerializable + public class LogDetailsModel : LogModel + { + public JObject Exception { get; set; } + + public string ExceptionToString(JObject e) { - [JsonProperty(PropertyName = "error")] - public string ErrorMessage { get; set; } + if(e == null) + { + return null; + } - [JsonConstructor] - public Error() { } + var val = string.Empty; + if(e["Message"] != null && e["Message"].ToObject() != null) + { + val += "Message:\n"; + val += e["Message"] + "\n"; + } + + if(e["StackTrace"] != null && e["StackTrace"].ToObject() != null) + { + val += "\nStackTrace:\n"; + val += e["StackTrace"]; + } + else if(e["StackTraceString"] != null && e["StackTraceString"].ToObject() != null) + { + val += "\nStackTraceString:\n"; + val += e["StackTraceString"]; + } + + if(e["InnerException"] != null && e["InnerException"].ToObject() != null) + { + val += "\n\n\n=== Inner Exception ===\n\n\n"; + val += ExceptionToString(e["InnerException"].ToObject()); + } + + return val; } } } diff --git a/src/Admin/Views/Logs/View.cshtml b/src/Admin/Views/Logs/View.cshtml index 151639a07..86ca77164 100644 --- a/src/Admin/Views/Logs/View.cshtml +++ b/src/Admin/Views/Logs/View.cshtml @@ -1,4 +1,4 @@ -@model LogModel +@model LogDetailsModel @{ ViewData["Title"] = "Log: " + Model.Id; } @@ -26,7 +26,7 @@ @if(Model.Exception != null) {

Exception

-
@Model.Exception.ToString()
+
@Model.ExceptionToString(Model.Exception)
} @if(Model.Properties != null && Model.Properties.Count > 0)