/// <summary> /// Action执行前 /// </summary> /// <param name="filterContext"></param> 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; //将日志监控对象存入当前这个Controller的ViewData视图中 }
public override void OnResultExecuted(ResultExecutedContext filterContext) { MonitorLog MonLog = filterContext.Controller.ViewData[Key] as MonitorLog; MonLog.ExecuteEndTime = DateTime.Now; LoggerHelper.Monitor(MonLog.GetLoginfo(MonitorLog.MonitorType.View)); //执行结束后清楚这个ViewData filterContext.Controller.ViewData.Remove(Key); }
/// <summary> /// Action执行后 /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuted(ActionExecutedContext filterContext) { MonitorLog MonLog = filterContext.Controller.ViewData[Key] as MonitorLog; MonLog.ExecuteEndTime = DateTime.Now; MonLog.FormCollections = filterContext.HttpContext.Request.Form; //form表单提交的数据 MonLog.QueryCollections = filterContext.HttpContext.Request.QueryString; //Url 参数 //Action执行完之后调用一次Log4net记录日志 LoggerHelper.Monitor(MonLog.GetLoginfo()); }
public override void OnResultExecuting(ResultExecutingContext filterContext) { MonitorLog MonLog = filterContext.Controller.ViewData[Key] as MonitorLog; MonLog.ExecuteStartTime = DateTime.Now; }