Browse Source

修改日志

zhoufan 4 years ago
parent
commit
79a84289c9

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

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

+ 22 - 1
codegit/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
20
             if (context == null)
21
             if (context == null)
21
                 return;
22
                 return;
22
             var log = LogFactory.GetLogger(context.Controller.ToString());
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
         /// </summary>
29
         /// </summary>
30
         public Log FileLog
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
         /// <summary>
35
         /// <summary>
40
         protected virtual ActionResult Success(string message)
40
         protected virtual ActionResult Success(string message)
41
         {
41
         {
42
             var jsonMsg = new AjaxResult { state = ResultTypes.success.ToString(), message = message }.ToJson();
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
             return Content(jsonMsg);
44
             return Content(jsonMsg);
45
         }
45
         }
46
 
46
 
53
         protected virtual ActionResult Success(string message, object data)
53
         protected virtual ActionResult Success(string message, object data)
54
         {
54
         {
55
             var jsonMsg = new AjaxResult { state = ResultTypes.success.ToString(), message = message,data=data }.ToJson();
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
             return Content(jsonMsg);
57
             return Content(jsonMsg);
58
         }
58
         }
59
 
59
 
76
         protected virtual ActionResult Error(string message)
76
         protected virtual ActionResult Error(string message)
77
         {
77
         {
78
             var jsonMsg = new AjaxResult { state = ResultTypes.error.ToString(), message = message }.ToJson();
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
             return Content(jsonMsg);
97
             return Content(jsonMsg);
81
         }
98
         }
82
 
99
 
88
         protected virtual ActionResult NoToken(string message)
105
         protected virtual ActionResult NoToken(string message)
89
         {
106
         {
90
             var jsonMsg = new AjaxResult { state = ResultTypes.notoken.ToString(), message = message }.ToJson();
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
             return Content(jsonMsg);
109
             return Content(jsonMsg);
93
         }
110
         }
94
 
111
 
100
         protected virtual ActionResult UnAuthorized(string message)
117
         protected virtual ActionResult UnAuthorized(string message)
101
         {
118
         {
102
             var jsonMsg = new AjaxResult { state = ResultTypes.unauthorized.ToString(), message = message }.ToJson();
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
             return Content(jsonMsg);
121
             return Content(jsonMsg);
105
         }
122
         }
106
 
123
 

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

1
 using log4net;
1
 using log4net;
2
+using System;
2
 
3
 
3
 namespace CallCenter.Utility
4
 namespace CallCenter.Utility
4
 {
5
 {
17
         {
18
         {
18
             this.logger.Error(RequestString.GetIP() + "  " + message);
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
         public void Info(object message)
25
         public void Info(object message)
21
         {
26
         {
22
             this.logger.Info(RequestString.GetIP() + "  " + message);
27
             this.logger.Info(RequestString.GetIP() + "  " + message);