/// <summary> /// Logs an error to the database for later review /// </summary> /// <returns>True if error logged ok</returns> public static bool Log(CMS_MainEntities context, Exception ex) { try { var errorReport = new ErrorReports { ExceptionMessage = ex.Message, StackTrace = ex.StackTrace }; MethodBase site = ex.TargetSite; errorReport.ModuleFunction = (site == null) ? "Unknown" : site.Name; errorReport.ModuleName = site == null ? "Unknown" : site.Module.Name; var baseException = ex.GetBaseException(); errorReport.BaseExceptionMessage = ((baseException.Message == "")) ? "No Message Available" : baseException.Message; errorReport.ErrorDate = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss tt"); errorReport.BugFixed = false; context.ErrorReports.Add(errorReport); context.SaveChanges(); return (true); } catch { return (false); } }
private void ListFilesAndSubFolders(DirectoryInfo di) { if (di == null) { throw new ArgumentNullException(nameof(di)); } try { var fsInfo = di.GetFileSystemInfos(); // Iterate through each item. foreach (var fsi in fsInfo) { #if SpecialFileHandling // skip files that have Hidden, System or Temporary file attributes if (((fsi.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) || ((fsi.Attributes & FileAttributes.System) == FileAttributes.System) || ((fsi.Attributes & FileAttributes.Temporary) == FileAttributes.Temporary)) { continue; } #endif switch (fsi) { case DirectoryInfo directoryInfo: ProcessDirectory(directoryInfo); break; case FileInfo fileInfo: ProcessFile(fileInfo); break; } } } catch (PathTooLongException e) { ErrorReports.Add(e.Message); } catch (ArgumentException e) { var msg = string.Concat(di.FullName, "\n", e.Message); ErrorReports.Add(msg); } catch (DirectoryNotFoundException e) { ErrorReports.Add(e.Message); } catch (SecurityException e) { ErrorReports.Add(e.Message); } catch (UnauthorizedAccessException e) { ErrorReports.Add(e.Message); } }
internal void AddSingleErrorReport(ErrorReport report) { ErrorReportViewModel reportVM = new ErrorReportViewModel() { Report = report }; ErrorReports.Add(reportVM); }
private void RefreshErrorReportsList() { ErrorReports.Clear(); try { foreach (ErrorReport report in ErrorReportManager.GetNewestReports(null, 0)) { AddSingleErrorReport(report); } } catch (DirectoryNotFoundException) { // Nothing - if the directory is not found, there just have been no errors yet. } }