Browse Source

修改日志

zhoufan 4 years ago
parent
commit
79a84289c9

+ 1 - 1
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/App_Start/AuthorizeAttribute.cs

@@ -68,7 +68,7 @@ namespace CallCenterApi.Interface
68 68
         {
69 69
             if (filterContext == null)
70 70
                 return;
71
-            var log = LogFactory.GetLogger(filterContext.Controller.ToString());
71
+            var log = LogFactory.GetLogger(filterContext.Controller.ToString() + "/" + filterContext.ActionDescriptor.ActionName);
72 72
             log.Error(filterContext.Result);
73 73
         }
74 74
 

+ 22 - 1
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/App_Start/ErrorAttribute.cs

@@ -1,4 +1,5 @@
1 1
 using CallCenter.Utility;
2
+using System.Collections.Generic;
2 3
 using System.Web.Mvc;
3 4
 
4 5
 namespace CallCenterApi.Interface
@@ -20,7 +21,27 @@ namespace CallCenterApi.Interface
20 21
             if (context == null)
21 22
                 return;
22 23
             var log = LogFactory.GetLogger(context.Controller.ToString());
23
-            log.Error(context.Exception.ToString());
24
+            //log.Error(context.Exception.ToString());
25
+
26
+            var cnt = context.RequestContext.HttpContext;
27
+            var rt = cnt.Request;
28
+            Dictionary<string, string> Params = new Dictionary<string, string>();
29
+            Params.Add("request_url", rt.Url.ToString());
30
+
31
+            if (rt.HttpMethod.ToUpper() != "GET")
32
+            {
33
+                foreach (var key in rt.Params.AllKeys)
34
+                {
35
+                    if (key == "ALL_HTTP")
36
+                    {
37
+                        break;
38
+                    }
39
+                    Params.Add(key, rt.Params[key]);
40
+                }
41
+            }
42
+            string usercode = cnt.User?.Identity.Name ?? "";
43
+
44
+            log.Error("系统异常,操作账号:" + usercode + ",请求信息:" + Params.ToJson(), context.Exception);
24 45
         }
25 46
     }
26 47
 }

+ 23 - 6
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/Base/BaseController.cs

@@ -29,7 +29,7 @@ namespace CallCenterApi.Interface.Controllers.Base
29 29
         /// </summary>
30 30
         public Log FileLog
31 31
         {
32
-            get { return LogFactory.GetLogger(this.GetType().ToString()); }
32
+            get { return LogFactory.GetLogger(this.GetType().ToString() + "/" + this.ControllerContext.RouteData.Values["Action"].ToString()); }
33 33
         }
34 34
 
35 35
         /// <summary>
@@ -40,7 +40,7 @@ namespace CallCenterApi.Interface.Controllers.Base
40 40
         protected virtual ActionResult Success(string message)
41 41
         {
42 42
             var jsonMsg = new AjaxResult { state = ResultTypes.success.ToString(), message = message }.ToJson();
43
-            FileLog.Info(jsonMsg);
43
+            FileLog.Info((CurrentUser?.UserData.F_UserCode ?? "") + "|" + jsonMsg);
44 44
             return Content(jsonMsg);
45 45
         }
46 46
 
@@ -53,7 +53,7 @@ namespace CallCenterApi.Interface.Controllers.Base
53 53
         protected virtual ActionResult Success(string message, object data)
54 54
         {
55 55
             var jsonMsg = new AjaxResult { state = ResultTypes.success.ToString(), message = message,data=data }.ToJson();
56
-            FileLog.Info(jsonMsg);
56
+            FileLog.Info((CurrentUser?.UserData.F_UserCode ?? "") + "|" + jsonMsg);
57 57
             return Content(jsonMsg);
58 58
         }
59 59
 
@@ -76,7 +76,24 @@ namespace CallCenterApi.Interface.Controllers.Base
76 76
         protected virtual ActionResult Error(string message)
77 77
         {
78 78
             var jsonMsg = new AjaxResult { state = ResultTypes.error.ToString(), message = message }.ToJson();
79
-            FileLog.Error(jsonMsg);
79
+
80
+            Dictionary<string, string> Params = new Dictionary<string, string>();
81
+            Params.Add("request_url", Request.Url.ToString());
82
+
83
+            if (Request.HttpMethod.ToUpper() != "GET")
84
+            {
85
+                foreach (var key in Request.Params.AllKeys)
86
+                {
87
+                    if (key == "ALL_HTTP")
88
+                    {
89
+                        break;
90
+                    }
91
+                    Params.Add(key, Request.Params[key]);
92
+                }
93
+            }
94
+
95
+            FileLog.Error((CurrentUser?.UserData.F_UserCode ?? "") + "|" + Params.ToJson() + "|" + jsonMsg);
96
+
80 97
             return Content(jsonMsg);
81 98
         }
82 99
 
@@ -88,7 +105,7 @@ namespace CallCenterApi.Interface.Controllers.Base
88 105
         protected virtual ActionResult NoToken(string message)
89 106
         {
90 107
             var jsonMsg = new AjaxResult { state = ResultTypes.notoken.ToString(), message = message }.ToJson();
91
-            FileLog.Info(jsonMsg);
108
+            FileLog.Info((CurrentUser?.UserData.F_UserCode ?? "") + "|" + jsonMsg);
92 109
             return Content(jsonMsg);
93 110
         }
94 111
 
@@ -100,7 +117,7 @@ namespace CallCenterApi.Interface.Controllers.Base
100 117
         protected virtual ActionResult UnAuthorized(string message)
101 118
         {
102 119
             var jsonMsg = new AjaxResult { state = ResultTypes.unauthorized.ToString(), message = message }.ToJson();
103
-            FileLog.Error(jsonMsg);
120
+            FileLog.Error((CurrentUser?.UserData.F_UserCode ?? "") + "|" + jsonMsg);
104 121
             return Content(jsonMsg);
105 122
         }
106 123
 

+ 5 - 0
codegit/CallCenterCommon/CallCenter.Utility/log/Log.cs

@@ -1,4 +1,5 @@
1 1
 using log4net;
2
+using System;
2 3
 
3 4
 namespace CallCenter.Utility
4 5
 {
@@ -17,6 +18,10 @@ namespace CallCenter.Utility
17 18
         {
18 19
             this.logger.Error(RequestString.GetIP() + "  " + message);
19 20
         }
21
+        public void Error(object message,Exception ex)
22
+        {
23
+            this.logger.Error(RequestString.GetIP() + "  " + message, ex);
24
+        }
20 25
         public void Info(object message)
21 26
         {
22 27
             this.logger.Info(RequestString.GetIP() + "  " + message);