/// <summary> /// Gets the related exception logs /// </summary> /// <param name="baseException">The base exception.</param> /// <returns>List of Exception Detail Summary objects</returns> private List <ExceptionLog> GetExceptionLogs(ExceptionLog baseException) { List <ExceptionLog> exceptionList = new List <ExceptionLog>(); ExceptionLogService svc = new ExceptionLogService(new RockContext()); //load the base exception exceptionList.Add(baseException); //get the parentID int?parentId = baseException.ParentId; //loop through exception hierarchy (parent, grandparent, etc) while (parentId != null && parentId > 0) { var exception = svc.Get((int)parentId); if (exception != null) { exceptionList.Add(exception); } parentId = exception.ParentId; } //get inner exceptions if (baseException.HasInnerException != null && (bool)baseException.HasInnerException) { exceptionList.AddRange(svc.GetByParentId(baseException.Id)); } return(exceptionList); }
/// <summary> /// Gets the related exception logs /// </summary> /// <param name="exception">The top-level exception.</param> /// <returns>List of Exception Detail Summary objects</returns> private List <ExceptionLog> GetExceptionLogs(ExceptionLog exception) { var exceptionList = new List <ExceptionLog>(); var dataContext = GetDataContext(); var exceptionService = new ExceptionLogService(dataContext); //load the base exception exceptionList.Add(exception); //get the parentID int?parentId = exception.ParentId; //loop through exception hierarchy (parent, grandparent, etc) while (parentId != null && parentId > 0) { var parentException = exceptionService.Get(( int )parentId); if (parentException != null) { exceptionList.Add(parentException); } parentId = parentException.ParentId; } //get inner exceptions if (exception.HasInnerException != null && ( bool )exception.HasInnerException) { exceptionList.AddRange(exceptionService.GetByParentId(exception.Id)); } return(exceptionList); }
/// <summary> /// Gets the related exception logs /// </summary> /// <param name="baseException">The base exception.</param> /// <returns>List of Exception Detial Summary objects</returns> private List <ExceptionDetailSummary> GetExceptionLogs(ExceptionLog baseException) { List <ExceptionDetailSummary> summaryList = new List <ExceptionDetailSummary>(); ExceptionLogService svc = new ExceptionLogService(); //load the base exception summaryList.Add(new ExceptionDetailSummary() { ExceptionId = baseException.Id, ExceptionSource = baseException.Source, ExceptionType = baseException.ExceptionType, ExceptionDescription = baseException.Description, StackTrace = baseException.StackTrace }); //get the parentID int?parentId = baseException.ParentId; //loop through exception hierachy (parent, grandparent, etc) while (parentId != null && parentId > 0) { var exception = svc.Get((int)parentId); if (exception != null) { summaryList.Add(new ExceptionDetailSummary() { ExceptionId = exception.Id, ExceptionSource = exception.Source, ExceptionType = exception.ExceptionType, ExceptionDescription = exception.Description, StackTrace = exception.StackTrace } ); } parentId = exception.ParentId; } //get inner excpetions if (baseException.HasInnerException != null && (bool)baseException.HasInnerException) { foreach (ExceptionLog exception in svc.GetByParentId(baseException.Id)) { summaryList.Add(new ExceptionDetailSummary() { ExceptionId = exception.Id, ExceptionSource = exception.Source, ExceptionType = exception.ExceptionType, ExceptionDescription = exception.Description, StackTrace = exception.StackTrace } ); } } return(summaryList); }
/// <summary> /// Gets the child exceptions recursive. /// </summary> /// <param name="exceptionLogService">The exception log service.</param> /// <param name="exceptionLog">The exception log.</param> /// <param name="exceptionLogs">The exception logs.</param> private void GetChildExceptionsRecursive(ExceptionLogService exceptionLogService, ExceptionLog exceptionLog, ref List <ExceptionLog> exceptionLogs) { if (exceptionLogs.Any(a => a.Id == exceptionLog.Id)) { // prevent stackoverflow just in case return; } exceptionLogs.Add(exceptionLog); if (exceptionLog.HasInnerException == true) { List <ExceptionLog> innerExceptions = exceptionLogService.GetByParentId(exceptionLog.Id).ToList(); foreach (var innerException in innerExceptions) { GetChildExceptionsRecursive(exceptionLogService, innerException, ref exceptionLogs); } } }