I've done the same thing you are talking about. I created an ErrorPage that displays info to the user. I also created a function that writes the error info into the Event Logs...
For the page, this is what I'm doing. Just put the labels on there somewhere...
protected void Page_Load(object sender, EventArgs e)
{
Exception ex = Server.GetLastError().GetBaseException();
this.lblMessage.Text = ex.Message;
this.lblSource.Text = ex.Source;
this.lblStackTrace.Text = ex.StackTrace;
if (AppProperties.AppEnv != AppEnvironment.PROD)
{
this.ErrorDetails.Visible = true;
}
else
{
this.ErrorDetails.Visible = false;
}
Utility.LogError();
Server.ClearError();
}
This is what the LogError function looks like...
public static void LogError()
{
LogError(HttpContext.Current.Server.GetLastError().GetBaseException());
}
public static void LogError(Exception ex)
{
EventLog log = new EventLog();
if (ex != null)
{
log.Source = ConfigurationManager.AppSettings["EventLog"].ToString();
StringBuilder sErrorMessage = new StringBuilder();
if (HttpContext.Current.Request != null && HttpContext.Current.Request.Url != null)
{
sErrorMessage.Append(HttpContext.Current.Request.Url.ToString() + System.Environment.NewLine);
}
sErrorMessage.Append(ex.ToString());
log.WriteEntry(sErrorMessage.ToString(), EventLogEntryType.Error);
}
}