Esempio n. 1
0
        public override void OnException(ExceptionContext filterContext)
        {
            base.OnException(filterContext);

            ErrorMessage msg = new ErrorMessage(filterContext.Exception, "页面");

            msg.ShowException = MvcException.IsExceptionEnabled();

            //错误记录
            string exMsg = JsonConvert.SerializeObject(msg, Formatting.Indented);

            NLogHelper.Default.Fatal(exMsg);

            //设置为true阻止golbal里面的错误执行
            //filterContext.ExceptionHandled = true;
            //filterContext.Result = new ViewResult() { ViewName = "/Views/Error/ISE.cshtml", ViewData = new ViewDataDictionary<ErrorMessage>(msg) };
        }
Esempio n. 2
0
        public override void OnException(HttpActionExecutedContext filterContext)
        {
            base.OnException(filterContext);

            //异常信息
            ErrorMessage msg = new ErrorMessage(filterContext.Exception, "接口");

            //接口调用参数
            msg.ActionArguments = JsonConvert.SerializeObject(filterContext.ActionContext.ActionArguments, Formatting.Indented);
            msg.ShowException   = MvcException.IsExceptionEnabled();

            //错误记录
            string exMsg = JsonConvert.SerializeObject(msg, Formatting.Indented);

            NLogHelper.Default.Fatal(exMsg);

            filterContext.Response = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(exMsg)
            };
        }