Sfoglia il codice sorgente

新增错误日志

zhoufan 4 anni fa
parent
commit
f1fd468021

+ 19 - 3
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/App_Start/ErrorAttribute.cs

1
 using CallCenter.Utility;
1
 using CallCenter.Utility;
2
+using System.Collections.Generic;
2
 using System.Web.Mvc;
3
 using System.Web.Mvc;
3
 
4
 
4
 namespace CallCenterApi.Interface
5
 namespace CallCenterApi.Interface
12
             WriteLog(context);
13
             WriteLog(context);
13
             context.ExceptionHandled = true;
14
             context.ExceptionHandled = true;
14
             context.HttpContext.Response.StatusCode = 200;
15
             context.HttpContext.Response.StatusCode = 200;
15
-            context.Result = new ContentResult { Content = new AjaxResult { state = ResultTypes.error.ToString(), message = context.Exception.ToString()}.ToJson() };
16
+            //context.Result = new ContentResult { Content = new AjaxResult { state = ResultTypes.error.ToString(), message = context.Exception.ToString()}.ToJson() };
17
+            context.Result = new ContentResult { Content = new AjaxResult { state = ResultTypes.error.ToString(), message = "系统异常,请稍后重试" }.ToJson() };
16
         }
18
         }
17
 
19
 
18
         private void WriteLog(ExceptionContext context)
20
         private void WriteLog(ExceptionContext context)
20
             if (context == null)
22
             if (context == null)
21
                 return;
23
                 return;
22
             var actionName = context.RouteData.Values["Action"];
24
             var actionName = context.RouteData.Values["Action"];
23
-            var log = LogFactory.GetLogger(context.Controller.ToString()+"/"+actionName);
24
-            log.Error(context.Exception.ToString());
25
+            var log = LogFactory.GetLogger(context.Controller.ToString() + "/" + actionName);
26
+
27
+            var rt = context.RequestContext.HttpContext.Request;
28
+            Dictionary<string, string> Params = new Dictionary<string, string>();
29
+            Params.Add("request_url", rt.Url.ToString());
30
+
31
+            foreach (var key in rt.Params.AllKeys)
32
+            {
33
+                if (key == "ALL_HTTP")
34
+                {
35
+                    break;
36
+                }
37
+                Params.Add(key, rt.Params[key]);
38
+            }
39
+
40
+            log.Error(Params.ToJson() + "\r\n" + context.Exception.ToString());
25
         }
41
         }
26
     }
42
     }
27
 }
43
 }