/// <summary> /// 写日志 /// </summary> /// <param name="actionContext">HttpActionContext</param> /// <param name="request">HttpRequestMessage</param> /// <param name="bc">BaseController</param> private void WriteLogInfo(HttpActionContext actionContext, HttpRequestMessage request, BaseController bc) { EUrlStatViewModel stat = new EUrlStatViewModel(); stat.RequestUrl = request.RequestUri.Authority + request.RequestUri.AbsolutePath; stat.RequestType = request.Method.Method; stat.SessionID = string.Empty; stat.ProSign = "MCP"; if (!actionContext.ActionArguments.ContainsKey("IP")) { actionContext.ActionArguments.Add("IP", CommonUtil.GetClientIp(actionContext.Request)); } else if (actionContext.Request.Headers.Contains("Coolwi-Header")) { actionContext.ActionArguments.Add("Client-Info", actionContext.Request.Headers.GetValues("Coolwi-Header")); //新版:保存请求头中自定义的客户端信息 } stat.ParamData = JsonUtil.Serialize(actionContext.ActionArguments); stat.Controller = actionContext.ActionDescriptor.ControllerDescriptor.ControllerName; stat.Action = actionContext.ActionDescriptor.ActionName; stat.SessionID = bc.Session.SessionID; if (ConfigUtil.IsLogToDb) { LogUtil.WriteDB(stat); } else { LogUtil.Info(JsonUtil.Serialize(stat)); } }
/// <summary> /// 获取EUrlStatViewModel对象 /// </summary> /// <param name="filterContext">AuthorizationContext</param> /// <returns></returns> private EUrlStatViewModel GetUrlStatViewModel(AuthorizationContext filterContext) { HttpRequestBase request = filterContext.HttpContext.Request; EUrlStatViewModel stat = new EUrlStatViewModel(); stat.RequestUrl = request.Url.Authority + request.Url.AbsolutePath; stat.RequestType = request.RequestType; stat.SessionID = filterContext.HttpContext.Session.SessionID; stat.ProSign = "MCP"; stat.ParamData = GetParamData(request); stat.HeaderParamData = GetHeadersParam(request); stat.UserId = SessionUtil.Current != null ? SessionUtil.Current.UserId : null; RequestClientInfoQueryModel mode = GetClientInfo(request); stat.DeviceId = mode.DeviceId; stat.DeviceType = mode.DeviceType; stat.Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName; stat.Action = filterContext.ActionDescriptor.ActionName; return(stat); }