public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { WebApiMonitorLog MonLog = actionExecutedContext.Request.Properties[Key] as WebApiMonitorLog; MonLog.ExecuteEndTime = DateTime.Now; MonLog.ActionName = actionExecutedContext.ActionContext.ActionDescriptor.ActionName; MonLog.ControllerName = actionExecutedContext.ActionContext.ActionDescriptor.ControllerDescriptor.ControllerName; LoggerHelper.Monitor(MonLog.GetLoginfo()); if (actionExecutedContext.Exception != null) { string Msg = string.Format(@" 请求【{0}Controller】的【{1}】产生异常: Action参数:{2} Http请求头:{3} 客户端IP:{4}, HttpMethod:{5} ", MonLog.ControllerName, MonLog.ActionName, MonLog.GetCollections(MonLog.ActionParams), MonLog.HttpRequestHeaders, MonLog.GetIP(), MonLog.HttpMethod); LoggerHelper.Error(Msg, actionExecutedContext.Exception); } }
public override void OnActionExecuted(ActionExecutedContext actionExecutedContext) { base.OnActionExecuted(actionExecutedContext); LogHelper.logpath = logpath; byte[] vs; if (!actionExecutedContext.HttpContext.Session.TryGetValue(Key, out vs)) { LogHelper.WriteErrorLog(null, "尝试获取值失败"); return; } WebApiMonitorLog MonLog = BytesToObject(vs) as WebApiMonitorLog; actionExecutedContext.HttpContext.Session.Clear(); MonLog.ExcuteEndTime = DateTime.Now; MonLog.ActionName = actionExecutedContext.RouteData.Values["Action"].ToString(); MonLog.ControllerName = actionExecutedContext.RouteData.Values["Controller"].ToString(); LogHelper.WriteLog(null, MonLog.GetLoginfo()); if (actionExecutedContext.Exception != null) { IDictionary <string, object> redataList = MonLog.ActionParams; string redata = string.Empty; foreach (string key in redataList.Keys) { redata += key + " , "; } string Msg = string.Format(@" 请求【{0}Controller】的【{1}】产生异常: Http请求头:{2} 客户端IP:{3}, 请求方法:{4} 请求参数:{5}", MonLog.ControllerName, MonLog.ActionName, MonLog.HttpRequestHeaders, MonLog.IP, MonLog.HttpMethod, redata); LogHelper.WriteErrorLog(actionExecutedContext.Exception, Msg); // throw new Exception("发生异常:" + actionExecutedContext.Exception.Message); } }
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { WebApiMonitorLog MonLog = actionExecutedContext.Request.Properties[Key] as WebApiMonitorLog; MonLog.ExecuteEndTime = DateTime.Now; MonLog.ActionName = actionExecutedContext.ActionContext.ActionDescriptor.ActionName; MonLog.ControllerName = actionExecutedContext.ActionContext.ActionDescriptor.ControllerDescriptor.ControllerName; LoggerHelper.Monitor(MonLog.UserName,MonLog.ActionUri.ToString(),MonLog.ActionName,MonLog.GetLoginfo()); if (actionExecutedContext.Exception != null) { LoggerHelper.Error(MonLog.UserName, MonLog.ActionUri.ToString(), MonLog.ActionName, MonLog.GetLoginfo(), actionExecutedContext.Exception); } }