public void OnException(ExceptionContext context)
        {
            //写入日志到数据库
            ExceptionLogHandler exceptionLog = new ExceptionLogHandler(context.Exception);

            exceptionLog.WriteLog();
            if (context.HttpContext.Request.Method.ToLower() == "post" || context.HttpContext.Request.Headers["x-requested-with"] == "XMLHttpRequest")
            {
                OperateResult result = new OperateResult("系统异常,请联系管理员处理", ResultStatus.Error);
                context.Result = new JsonResult(result);
            }
            else
            {
                //跳转至错误页
                context.HttpContext.Response.WriteAsync("<script type=\"text/javascript\">top.location.href = '/Main/Login/Index'</script>");
            }
        }
Esempio n. 2
0
        public void OnException(ExceptionContext context)
        {
            var logger = _loggerFactory.CreateLogger(context.Exception.TargetSite.ReflectedType);

            logger.LogError(new EventId(context.Exception.HResult),
                            context.Exception,
                            context.Exception.Message);
            var json = new OperateStatus();

            if (_env.IsDevelopment())
            {
                json.Message = context.Exception;
            }
            //记录日志到MongoDb
            ExceptionLogHandler handler = new ExceptionLogHandler(context.Exception, _accessor,
                                                                  _currentUser);

            handler.WriteLog();
        }
Esempio n. 3
0
        /// <summary>
        ///   异常发生记录日志
        /// </summary>
        /// <param name="context"></param>
        public void OnException(ExceptionContext context)
        {
            ExceptionLogHandler exceptionLogHandler = new ExceptionLogHandler(context.Exception);

            Task.Factory.StartNew(() => exceptionLogHandler.WriteLog());
        }