84 lines
3.3 KiB
C#
84 lines
3.3 KiB
C#
using System.Data.Entity.Validation;
|
|
using System.Text;
|
|
using EnVisage.Code;
|
|
using EnVisage.Code.BLL;
|
|
using EnVisage.Models;
|
|
using NLog;
|
|
using jQuery.DataTables.Mvc;
|
|
using System;
|
|
using System.Data.Entity;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using System.Web.Optimization;
|
|
using System.Web.Routing;
|
|
|
|
namespace EnVisage
|
|
{
|
|
public class MvcApplication : System.Web.HttpApplication
|
|
{
|
|
protected void Application_Start()
|
|
{
|
|
Database.SetInitializer<ApplicationDbContext>(null);
|
|
AreaRegistration.RegisterAllAreas();
|
|
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
|
|
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
|
ModelBinders.Binders.Add(typeof(JQueryDataTablesModel), new JQueryDataTablesModelBinder());
|
|
}
|
|
|
|
protected void Application_Error(object sender, EventArgs e)
|
|
{
|
|
var exception = Server.GetLastError();
|
|
if (exception == null)
|
|
return;
|
|
var sb = new StringBuilder();
|
|
sb.AppendLine(string.Format("{0}: {1}", exception.GetType(), exception.Message));
|
|
sb.AppendLine(exception.StackTrace);
|
|
|
|
var innerCount = 0;
|
|
var innerEx = exception;
|
|
while (innerEx.InnerException != null && innerCount++ < Constants.MAX_INNER_EXCEPTION_LOG_LEVEL)
|
|
{
|
|
if (innerEx.Message != innerEx.InnerException.Message)
|
|
sb.AppendLine("Inner Exception Message: " + exception.InnerException.Message);
|
|
innerEx = innerEx.InnerException;
|
|
}
|
|
if (exception is DbEntityValidationException)
|
|
{
|
|
sb.AppendLine();
|
|
foreach (var validationErrors in ((DbEntityValidationException)exception).EntityValidationErrors)
|
|
{
|
|
|
|
foreach (var validationError in validationErrors.ValidationErrors)
|
|
{
|
|
sb.AppendFormat("Property: {0} Error: {1}", validationError.PropertyName,
|
|
validationError.ErrorMessage);
|
|
|
|
}
|
|
}
|
|
sb.AppendLine(exception.StackTrace);
|
|
}
|
|
if (HttpContext.Current != null)
|
|
{
|
|
sb.AppendLine();
|
|
sb.AppendLine(string.Format("URL: {0}", HttpContext.Current.Request.Url));
|
|
sb.AppendLine(string.Format("Referrer: {0}", HttpContext.Current.Request.UrlReferrer));
|
|
sb.AppendLine(string.Format("QueryString: {0}", HttpContext.Current.Request.QueryString));
|
|
sb.AppendLine(string.Format("UserHostAddress: {0}", HttpContext.Current.Request.UserHostAddress));
|
|
sb.AppendLine(string.Format("UserAgent: {0}", HttpContext.Current.Request.UserAgent));
|
|
if (HttpContext.Current.Request.Form.Count > 0)
|
|
{
|
|
sb.AppendLine();
|
|
sb.AppendLine("Form:");
|
|
foreach (string key in HttpContext.Current.Request.Form.Keys)
|
|
{
|
|
sb.AppendLine(string.Format("{0}: {1}", key, HttpContext.Current.Request.Form[key]));
|
|
}
|
|
}
|
|
}
|
|
var logger = LogManager.GetCurrentClassLogger();
|
|
if (logger != null)
|
|
logger.Fatal(sb.ToString());
|
|
}
|
|
}
|
|
}
|