/// <summary> /// Logs the error into the database /// </summary> /// <param name="pageName">The name of the page that the error occurred on</param> /// <param name="stepName">The step or method that the error occurred within</param> /// <param name="errorCode">The unique error code for the error for debugging</param> /// <param name="details">The Exception with stacktrace if available or other details to include</param> public ApplicationErrors2 logError(string pageName, string stepName, string errorCode, string details) { IUser user = (IUser)HttpContext.Current.Session["User"]; if (user == null) user = (IUser)COMET.Controllers.ContextController.getContext().Session["User"]; if (user == null) { string userNT = Environment.UserName.ToLower(); if (userNT.Length > 0 && !userNT.ToLower().Equals("iusr")) { COMET.Model.Business.Manager.UserMgr userMgr = new COMET.Model.Business.Manager.UserMgr(MainFactory.getUserSvc()); user = userMgr.getUser(userNT); } } ApplicationErrors2 ae = new ApplicationErrors2 { ApplicationName = (string)MainFactory.getConfiguration().get("application"), PageName = pageName, StepName = stepName, EmployeeID = user.EmployeeID, ErrorTime = DateTime.Now, ErrorCode = errorCode, ErrorDetails = details }; try { using (UserDataContext dc = (UserDataContext)MainFactory.getDb("User", false)) { dc.ApplicationErrors2s.InsertOnSubmit(ae); dc.SubmitChanges(); } } catch (SqlException se) { EmailSvc.EmailError(ae, se.Message + "<br>" + se.StackTrace, ae.ErrorDetails); } return ae; }
/// <summary> /// Emails the Error to the team /// <see cref="COMET.Model.Business.Service.Email"/> /// </summary> /// <param name="ae">The Application Error that failed to insert into the database</param> /// <param name="insertException">The Exception that occurred trying to insert into the table</param> /// <param name="mainException">The Exception that occurred during client transaction</param> public static void EmailError(ApplicationErrors2 ae, string insertException, string mainException) { string user = ae.EmployeeID == 0 || ae.EmployeeID == 999999 ? ContextController.getContextUser().NTLogin : ae.EmployeeID.ToString(); string msgBody = "<html><body><table style=\"font-family:Arial;font-size:9pt;border-collapse:collapse;border:solid .5pt;border-color:RGB(150,150,150);padding-left:10px;padding-right:10px;\">"; msgBody = msgBody + "<tr><td style=\"border:solid .5pt RGB(150,150,150);padding-left:10px;padding-right:10px;\" align=\"left\">Application: </td><td align=\"right\">" + ae.ApplicationName + "</td></tr>"; msgBody = msgBody + "<tr><td style=\"border:solid .5pt RGB(150,150,150);padding-left:10px;padding-right:10px;\" align=\"left\">Page: </td><td align=\"right\">" + ae.PageName + "</td></tr>"; msgBody = msgBody + "<tr><td style=\"border:solid .5pt RGB(150,150,150);padding-left:10px;padding-right:10px;\" align=\"left\">Step: </td><td align=\"right\">" + ae.StepName + "</td></tr>"; msgBody = msgBody + "<tr><td style=\"border:solid .5pt RGB(150,150,150);padding-left:10px;padding-right:10px;\" align=\"left\">User: </td><td align=\"right\">" + user + "</td></tr>"; msgBody = msgBody + "<tr><td style=\"border:solid .5pt RGB(150,150,150);padding-left:10px;padding-right:10px;\" align=\"left\">Error Time: </td><td align=\"right\">" + ae.ErrorTime + "</td></tr>"; msgBody = msgBody + "<tr><td style=\"border:solid .5pt RGB(150,150,150);padding-left:10px;padding-right:10px;\" align=\"left\">Code: </td><td align=\"right\">" + ae.ErrorCode + "</td></tr></table>"; msgBody = msgBody + "<br><br><b>Details: </b><br>" + mainException + "<br /><br /><b>Error relating to DB insert</b> <br />" + insertException + "</body></html>"; Email((string) new Configuration().get("EmailTo"), "", "Comet Error", msgBody); }
partial void DeleteApplicationErrors2(ApplicationErrors2 instance);
partial void UpdateApplicationErrors2(ApplicationErrors2 instance);
partial void InsertApplicationErrors2(ApplicationErrors2 instance);
private void detach_ApplicationErrors2s(ApplicationErrors2 entity) { this.SendPropertyChanging(); entity.XXHR = null; }