protected void Application_Error() { var ex = Server.GetLastError(); Metrics.Exception(ex); using (var db = new email2sms.Data.Email2SmsContext()) { db.Errors.Add(new Data.ErrorRow { User = User.Identity.Name, TimeUtc = DateTime.UtcNow, Message = ex.Message, Stack = ex.ToString() }); db.SaveChanges(); } }
public override void OnException(HttpActionExecutedContext context) { Metrics.Exception(context.Exception); //Log Critical errors using (var db = new email2sms.Data.Email2SmsContext()) { db.Errors.Add(new Data.ErrorRow { User = context.ActionContext.RequestContext.Principal.Identity.Name, TimeUtc = DateTime.UtcNow, Message = context.Exception.Message, Stack = context.Exception.ToString() }); db.SaveChanges(); } throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("An error occurred, please try again or contact the administrator."), ReasonPhrase = "Critical Exception" }); }