Custom application error tracking through global.asax file
Here it goes :-
void Application_Error(object sender, EventArgs e) { string strError = "Error in: " + Request.Path + "<br>Url: " + Request.RawUrl + "<br><br>"; // Get the exception object for the last error message that occured. Exception ErrorInfo = Server.GetLastError().GetBaseException(); strError += "Error Message: " + ErrorInfo.Message + "<br>Error Source: " + ErrorInfo.Source + "<br>Error Target Site: " + ErrorInfo.TargetSite + "<br>IP: " + Request.ServerVariables["Remote_Addr"] + //Gathering IP "<br><br>QueryString Data:<br>-----------------<br>"; // Gathering QueryString information for (int i = 0; i < Context.Request.QueryString.Count; i++) strError += Context.Request.QueryString.Keys[i] + ": " + Context.Request.QueryString[i] + "<br>"; strError += "<br>Post Data:<br>----------<br>"; // Gathering Post Data information for (int i = 0; i < Context.Request.Form.Count; i++) strError += Context.Request.Form.Keys[i] + ": " + Context.Request.Form[i] + "<br>"; strError += "<br>"; if (User.Identity.IsAuthenticated) strError += "User: " + User.Identity.Name + "<br><br>"; strError += "Exception Stack Trace:<br>----------------------<br>" + Server.GetLastError().StackTrace + "<br><br>Server Variables:<br>-----------------<br>"; // Gathering Server Variables information for (int i = 0; i < Context.Request.ServerVariables.Count; i++) strError += Context.Request.ServerVariables.Keys[i] + ": " + Context.Request.ServerVariables[i] + "<br>"; strError += "<br>"; if (strError.IndexOf("does not exist.") == -1) { clsMail objMail = new clsMail(); //Your email class objMail.To = "ToEmai;"; objMail.From = "FromEmail"; objMail.Subject = "error has occured"; objMail.Body = strError; objMail.sendMail(); } }
