Example #1
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            base.OnActionExecuting(actionContext);
            if (site.WebAPITracker)
            {
                WebApiMonitorLog MonLog = new WebApiMonitorLog();
                MonLog.ExecuteStartTime = DateTime.Now;
                //获取Action 参数
                MonLog.ActionParams       = actionContext.ActionArguments;
                MonLog.HttpRequestHeaders = actionContext.Request.Headers.ToString();
                MonLog.HttpMethod         = actionContext.Request.Method.Method;

                actionContext.Request.Properties[Key] = MonLog;
                var form = System.Web.HttpContext.Current.Request.Form;
                #region 如果参数是实体对象,获取序列化后的数据
                Stream   stream   = actionContext.Request.Content.ReadAsStreamAsync().Result;
                Encoding encoding = Encoding.UTF8;
                stream.Position = 0;
                string responseData = "";
                //启用下面的代码接口上传文件将会报错
                //using (StreamReader reader = new StreamReader(stream, encoding))
                //{
                //    responseData = reader.ReadToEnd().ToString();
                //}
                if (!string.IsNullOrWhiteSpace(responseData) && !MonLog.ActionParams.ContainsKey("__EntityParamsList__"))
                {
                    MonLog.ActionParams["__EntityParamsList__"] = responseData;
                }
                #endregion
            }
        }
Example #2
0
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            base.OnActionExecuted(actionExecutedContext);
            if (site.WebAPITracker)
            {
                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;
                MonLog.Uri            = actionExecutedContext.Request.RequestUri.OriginalString;

                new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
                {
                    BLL.BaseBLL <Entity.SysLogApiAction> bll = new BLL.BaseBLL <Entity.SysLogApiAction>();
                    DateTime now_date = DateTime.Now.Date;
                    bll.DelBy(p => p.ExecuteStartTime < now_date);
                    bll.Add(MonLog.GetLogEntity());
                }))
                {
                    IsBackground = true
                }.Start();
            }
        }