コード例 #1
0
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            RequestLogs logs = new RequestLogs()
            {
                Id          = SequenceID.GetSequenceID(),
                ApiName     = context.HttpContext.Request.GetEncodedUrl(),
                IP          = context.HttpContext.Connection.RemoteIpAddress.ToString(),
                Headers     = JsonConvert.SerializeObject(context.HttpContext.Request.Headers),
                QueryString = context.HttpContext.Request.QueryString.Value,
                StatusCode  = context.HttpContext.Response.StatusCode,
                Result      = JsonConvert.SerializeObject(context.Result)
            };
            string token = context.HttpContext.Request.Headers["Authorization"];

            if (!string.IsNullOrEmpty(token))
            {
                if (AuthRedis.GetUserByToken(token, out UserInfo userInfo))
                {
                    logs.UID = userInfo.id;
                }
            }
            DBRequestLogs _logs = new DBRequestLogs();

            _logs.Create(logs);
        }
コード例 #2
0
        // [AuthFilter]//身份认证,不带token或者token错误会被拦截器拦截进不来这个接口
        public IActionResult GetMongoDB(DateTime StartTime, DateTime EndTime, int Skip, int limit)
        {
            DBRequestLogs _logs = new DBRequestLogs();
            var           list  = _logs.Get(StartTime, EndTime, Skip, limit).GroupBy(x => x.ApiName.Split("?")[0]);
            Dictionary <string, Dictionary <DateTime, int> > Time = new Dictionary <string, Dictionary <DateTime, int> >();

            foreach (var item in list)
            {
                foreach (var Citem in item.GroupBy(x => x.CreateTime.Day))
                {
                    TimeDto timeDto = new TimeDto()
                    {
                        DateTime = Citem.Key, Count = Citem.Count()
                    };
                    List <TimeDto> ChangeTiem = new List <TimeDto>();
                    ChangeTiem.Add(timeDto);
                    Time.Add(item.Key + Citem.Key, SequenceID.CompletionTime(StartTime, EndTime, ChangeTiem));
                }
            }
            return(Ok(new ApiResponse(Time, Time.Count())));
        }