Exemplo n.º 1
0
        protected virtual ActionResult WhenError(Exception e)
        {
            e.AddLog(this.GetType());

            //捕获的错误
            return(GetJsonRes(e.GetInnerExceptionAsJson()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 错误日志
        /// </summary>
        public static void AddErrorLog(this Exception e, string extra_data = null)
        {
            string ExceptionJson()
            {
                try
                {
                    return(JsonHelper.ObjectToJson(e));
                }
                catch (Exception err)
                {
                    return($"无法把整个{nameof(Exception)}对象转为json,原因:{err.Message}");
                }
            }

            using (var s = IocContext.Instance.Scope())
            {
                var data = new
                {
                    error_msg      = e.GetInnerExceptionAsList(),
                    exception_type = $"异常类型:{e.GetType()?.FullName}",
                    full_exception = LogFullException(s) ? ExceptionJson() : string.Empty,
                    req_data       = ReqData(),
                    extra_data     = extra_data,
                    friendly_time  = FriendlyTime(),
                    tips           = new string[] { "建议使用json格式化工具:http://json.cn/" }
                };
                e.AddLog(LoggerName(s), data);
            }
        }
Exemplo n.º 3
0
        protected virtual ActionResult WhenError(Exception e)
        {
            var(area, controller, action) = this.RouteData.GetA_C_A();
            e.AddLog(this.GetType());

            //捕获的错误
            return(GetJsonRes(e.GetInnerExceptionAsJson()));
        }
Exemplo n.º 4
0
        protected virtual ActionResult WhenError(Exception e)
        {
            var(area, controller, action) = this.RouteData.GetA_C_A();
            e.AddLog(this.GetType());

            var custom_error = this.ErrorResult?.Invoke();

            if (custom_error != null)
            {
                return(custom_error);
            }

            //捕获的错误
            if (this.ShowExceptionResult)
            {
                return(GetJsonRes(e.GetInnerExceptionAsJson()));
            }

            return(GetJsonRes("服务器发生错误"));
        }