diff --git a/Disco.Services/Jobs/JobLists/ManagedJobList.cs b/Disco.Services/Jobs/JobLists/ManagedJobList.cs index 3490adb1..a52f7788 100644 --- a/Disco.Services/Jobs/JobLists/ManagedJobList.cs +++ b/Disco.Services/Jobs/JobLists/ManagedJobList.cs @@ -2,6 +2,8 @@ using Disco.Data.Repository.Monitor; using Disco.Models.Repository; using Disco.Models.Services.Jobs.JobLists; +using Disco.Services.Authorization; +using Disco.Services.Jobs.JobQueues; using Disco.Services.Logging; using Disco.Services.Users; using System; @@ -12,10 +14,8 @@ using System.Reactive.Linq; namespace Disco.Services.Jobs.JobLists { using FilterFunc = Func, IQueryable>; - using SortFunc = Func, IEnumerable>; using OpenFilterFunc = Func, IEnumerable>; -using Disco.Services.Authorization; - using Disco.Services.Jobs.JobQueues; + using SortFunc = Func, IEnumerable>; public class ManagedJobList : JobTableModel, IDisposable { @@ -87,7 +87,7 @@ using Disco.Services.Authorization; allJobs = allJobs.Concat(queueJobs).ToList(); else allJobs = queueJobs.ToList(); - + var allJobsSorted = allJobs .OrderByDescending(i => i.Item2).ThenByDescending(i => i.Item3).ThenBy(i => i.Item4).ThenBy(i => i.Item1.OpenedDate).Select(q => q.Item1); diff --git a/Disco.Services/Logging/SystemLog.cs b/Disco.Services/Logging/SystemLog.cs index ab1e03e8..76426728 100644 --- a/Disco.Services/Logging/SystemLog.cs +++ b/Disco.Services/Logging/SystemLog.cs @@ -1,4 +1,5 @@ using Disco.Services.Logging.Models; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Text; @@ -44,10 +45,8 @@ namespace Disco.Services.Logging public static void LogException(string Component, Exception ex) { // Handle Special-Case Errors - if (ex is System.Data.Entity.Validation.DbEntityValidationException) + if (ex is System.Data.Entity.Validation.DbEntityValidationException dbException) { - var dbException = (System.Data.Entity.Validation.DbEntityValidationException)ex; - StringBuilder message = new StringBuilder(); message.AppendLine("Validation failed for one or more entities:"); foreach (var dbEntityError in dbException.EntityValidationErrors) @@ -64,7 +63,15 @@ namespace Disco.Services.Logging { if (ex.InnerException != null) { - Log(EventTypeIds.ExceptionWithInner, Component, ex.GetType().Name, ex.Message, ex.StackTrace, ex.InnerException.GetType().Name, ex.InnerException.Message, ex.InnerException.StackTrace); + // serialize inner exceptions for advanced troubleshooting + var serialized = string.Empty; + try + { + serialized = JsonConvert.SerializeObject(new SerializedException(ex, 5)); + } + catch (Exception) { } + + Log(EventTypeIds.ExceptionWithInner, Component, ex.GetType().Name, ex.Message, ex.StackTrace, ex.InnerException.GetType().Name, ex.InnerException.Message, ex.InnerException.StackTrace, serialized); } else { @@ -72,6 +79,54 @@ namespace Disco.Services.Logging } } } + private class SerializedException + { + public string Type { get; set; } + public string Message { get; set; } + public string StackTrace { get; set; } + public List Children { get; set; } + + public SerializedException(Exception ex, int depth) + { + Type = ex.GetType().Name; + StackTrace = ex.StackTrace; + Message = ex.Message; + + if (ex is System.Data.Entity.Validation.DbEntityValidationException dbException) + { + StringBuilder message = new StringBuilder(); + message.AppendLine("Validation failed for one or more entities:"); + foreach (var dbEntityError in dbException.EntityValidationErrors) + { + message.Append("'").Append(dbEntityError.Entry.Entity.GetType().Name).AppendLine("' Object"); + foreach (var dbValidationError in dbEntityError.ValidationErrors) + { + message.Append(" ").Append(dbValidationError.PropertyName).Append(": ").AppendLine(dbValidationError.ErrorMessage); + } + } + Message = message.ToString(); + } + + if (depth > 0) + { + if (ex is AggregateException exAg) + { + Children = new List(); + foreach (var inner in exAg.InnerExceptions) + { + Children.Add(new SerializedException(inner, depth - 1)); + } + } + else if (ex.InnerException != null) + { + Children = new List() + { + new SerializedException(ex.InnerException, depth - 1) + }; + } + } + } + } public static void LogLogInitialized(string PersistantStorePath) {