public override void OnActionExecuting(ActionExecutingContext filterContext) { MonitorLog MonLog = new MonitorLog(); MonLog.ExecuteStartTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.ffff", DateTimeFormatInfo.InvariantInfo)); MonLog.ControllerName = filterContext.RouteData.Values["controller"] as string; MonLog.ActionName = filterContext.RouteData.Values["action"] as string; filterContext.Controller.ViewData[Key] = MonLog; }
public override void OnActionExecuted(ActionExecutedContext filterContext) { MonitorLog MonLog = filterContext.Controller.ViewData[Key] as MonitorLog; MonLog.FormCollections = filterContext.HttpContext.Request.Form; //form表单提交的数据 MonLog.QueryCollections = filterContext.HttpContext.Request.QueryString; //Url 参数 MonLog.Url = filterContext.RouteData.Values["controller"] as string + "/" + filterContext.RouteData.Values["action"] as string + "?" + filterContext.HttpContext.Request.QueryString; MonLog.UserAddress = filterContext.HttpContext.Request.UserHostAddress; //LoggerHelper.Monitor(MonLog.GetLoginfo()); }
public override void OnResultExecuted(ResultExecutedContext filterContext) { MonitorLog MonLog = filterContext.Controller.ViewData[Key] as MonitorLog; MonLog.ExecuteEndTime = DateTime.Now; foreach (var item in filterContext.Result.GetType().GetProperties()) { object n = item.GetValue(filterContext.Result, null); string name = item.Name.ToLower(); if (n != null && name == "content") { MonLog.Response = System.Web.Helpers.Json.Encode(n); } } LoggerHelper.Monitor(MonLog.GetLoginfo(MonitorLog.MonitorType.View)); filterContext.Controller.ViewData.Remove(Key); }