1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| protected void Application_OnError()
{
Exception objErr = Server.GetLastError().GetBaseException();
string strErr = objErr.ToString();
if (objErr.InnerException != null)
strErr += "\r\nInnerException: \r\n" + objErr.InnerException;
strErr += "\r\nMESSAGE: " + objErr.Message +
"\r\nSOURCE: " + objErr.Source +
"\r\nQUERYSTRING: " + Request.QueryString.ToString() +
"\r\nTARGETSITE: " + objErr.TargetSite;
// Donner permissions a aspnet pour HKLM\SYSTEM\CurrentControlSet\Services\Eventlog\
// Creation of event log if it does not exist *=> Must exist !!
if (!EventLog.SourceExists("Extranet"))
EventLog.CreateEventSource(ConfigurationManager.AppSettings["LogSource"], ConfigurationManager.AppSettings["LogName"]);
// Inserting into event log
EventLog Log = new EventLog();
Log.Source = ConfigurationManager.AppSettings["LogSource"];
Log.WriteEntry(strErr, EventLogEntryType.Error);
string strMailTo = "";
string strMailSubject = "ERREUR";
strMailSubject += " - [ " + User.Identity.Name.ToString() + " ]";
string strMailBody = "";
strMailBody += strErr;
Courriel myCourriel = new Courriel();
myCourriel.SendMail(GlobalTools.TypeCourriel.TypeErreur, strMailTo, strMailSubject, strMailBody);
} |