Recent Posts

Thursday, August 21, 2008

How to handle and log Asp.Net Error in Event Viewer ?

You can just use the following to descently handle you error messages and log the error in the event viewer .

Also if you want to add the email function in the function.

the following code is the simplest way to handle error messages in

using System;
using System.Diagnostics;

void Page_Error(Object sender, EventArgs args)
Exception e = Server.GetLastError();

EventLog.WriteEntry("Test Web",
"MESSAGE: " + e.Message +
"\nSOURCE: " + e.Source +
"\nFORM: " + Request.Form.ToString() +
"\nQUERYSTRING: " + Request.QueryString.ToString() +
"\nTARGETSITE: " + e.TargetSite +
"\nSTACKTRACE: " + e.StackTrace,

Trace.Write("Message", e.Message);
Trace.Write("Source", e.Source);
Trace.Write("Stack Trace", e.StackTrace);
Response.Write("Sorry, an error was encountered.");

Related Posts by Categories

No comments:

Post a Comment