I did some more digging. Here is the actual code:
protected void Application_Error(object sender, EventArgs e)
{
Exception objErr = new Exception();
objErr = Server.GetLastError().GetBaseException();
int EventID = 62300;
string err = "Error In: " + Request.Url.ToString() + "\r\n"
+ "Error Source: " + objErr.Source.ToString() + "\r\n"
+ "Error Message: " + objErr.Message.ToString() + "\r\n"
+ "Stack Trace: " + objErr.StackTrace.ToString() + "\r\n";
System.Diagnostics.EventLog.WriteEntry("MyApp", err,
System.Diagnostics.EventLogEntryType.Error, EventID);
Server.ClearError();
MailMessage mailMsg = new MailMessage();
mailMsg.From = new MailAddress("er***@XXXX.com");
mailMsg.To.Add("ab*@XXXX.com");
mailMsg.Subject = "Event ID " + EventID.ToString()
+ " in Application MyApp";
mailMsg.Body = err;
SmtpClient smtp = new SmtpClient("smtp.XXXX.com");
smtp.Credentials = new System.Net.NetworkCredential(
"UID", "PWD");
smtp.EnableSsl = true;
smtp.Send(mailMsg);
Response.Write("An error occured in the MyApp. "
+ "An e-mail alert was sent to support staff. "
+ "Please quote EVENT ID: " + EventID.ToString()
+ " when following up with customer support");
}
When I commented out:
System.Diagnostics.EventLog.WriteEntry("MyApp", err,
System.Diagnostics.EventLogEntryType.Error, EventID);
The email message was sent out. off course the event was not logged. So I am
assuming here that this boils down to a rights problem. so I reactivated
writing to the event log and gave ASPNET user Administrator priviledges. That
did not work.
Any Suggestions?