Code below is used in Global.asax to log error is ASP.NET MVC3 application.
Some errors are realated to timeouts reading data from PostgreSql server.
How to add request duration logging to this ? Is there some propaerty which provides request start time in MVC3 ?
I looked into samples in
http://www.codeproject.com/Articles/550510/Exception-Handling-and-NET
http://msdn.microsoft.com/en-us/library/24395wz3(v=vs.100).aspx
Global.asax - Application_Error - How can I get Page data?
but havent found such sample.
void Application_Error(object sender, EventArgs e)
{
var sb = new StringBuilder();
var url = HttpContext.Current.Request.Url;
sb.AppendLine("Url " + url.ToString());
foreach (var d in Request.Form.AllKeys)
sb.AppendLine(d.ToString() + ":" + Request.Form[d].ToString());
sb.AppendLine();
foreach (var d in Request.Headers.AllKeys)
sb.AppendLine(d.ToString() + "\t" + Request.Headers[d].ToString());
Exception exception = Server.GetLastError();
MyLogger.WriteException(exception, "Application_Error", sb.ToString());
}