Custom application error tracking through global.asax file

Posted on October 22 2009 by Sachin Jain

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();
 
}
 
}
VN:F [1.9.0_1079]
Rating: 4.0/5 (1 vote cast)
VN:F [1.9.0_1079]
Rating: 0 (from 0 votes)
Custom application error tracking through global.asax file, 4.0 out of 5 based on 1 rating

Leave a Reply

Get Adobe Flash playerPlugin by wpburn.com wordpress themes

Powered by Sachin Jain

Powered by Olark