public object Any(RequestLogs request)
        {
            if (RequestLogger == null)
                throw new Exception("No IRequestLogger is registered");

            if (!HostContext.DebugMode)
            {
                RequiredRoleAttribute.AssertRequiredRoles(Request, RequestLogger.RequiredRoles);
            }

            if (request.EnableSessionTracking.HasValue)
                RequestLogger.EnableSessionTracking = request.EnableSessionTracking.Value;

            var now = DateTime.UtcNow;
            var logs = RequestLogger.GetLatestLogs(request.Take).AsQueryable();

            if (request.BeforeSecs.HasValue)
                logs = logs.Where(x => (now - x.DateTime) <= TimeSpan.FromSeconds(request.BeforeSecs.Value));
            if (request.AfterSecs.HasValue)
                logs = logs.Where(x => (now - x.DateTime) > TimeSpan.FromSeconds(request.AfterSecs.Value));
            if (!request.IpAddress.IsNullOrEmpty())
                logs = logs.Where(x => x.IpAddress == request.IpAddress);
            if (!request.UserAuthId.IsNullOrEmpty())
                logs = logs.Where(x => x.UserAuthId == request.UserAuthId);
            if (!request.SessionId.IsNullOrEmpty())
                logs = logs.Where(x => x.SessionId == request.SessionId);
            if (!request.Referer.IsNullOrEmpty())
                logs = logs.Where(x => x.Referer == request.Referer);
            if (!request.PathInfo.IsNullOrEmpty())
                logs = logs.Where(x => x.PathInfo == request.PathInfo);
            if (!request.Ids.IsEmpty())
                logs = logs.Where(x => request.Ids.Contains(x.Id));
            if (request.BeforeId.HasValue)
                logs = logs.Where(x => x.Id <= request.BeforeId);
            if (request.AfterId.HasValue)
                logs = logs.Where(x => x.Id > request.AfterId);
            if (request.WithErrors.HasValue)
                logs = request.WithErrors.Value
                    ? logs.Where(x => x.ErrorResponse != null)
                    : logs.Where(x => x.ErrorResponse == null);
            if (request.DurationLongerThan.HasValue)
                logs = logs.Where(x => x.RequestDuration > request.DurationLongerThan.Value);
            if (request.DurationLessThan.HasValue)
                logs = logs.Where(x => x.RequestDuration < request.DurationLessThan.Value);

            var results = logs.Skip(request.Skip).OrderByDescending(x => x.Id).ToList();

            return new RequestLogsResponse {
                Results = results,
                Usage = Usage,
            };
        }
Exemple #2
0
        public async Task <object> Any(RequestLogs request)
        {
            if (RequestLogger == null)
            {
                throw new Exception("No IRequestLogger is registered");
            }

            if (!HostContext.DebugMode)
            {
                await RequiredRoleAttribute.AssertRequiredRolesAsync(Request, RequestLogger.RequiredRoles);
            }

            if (request.EnableSessionTracking.HasValue)
            {
                RequestLogger.EnableSessionTracking = request.EnableSessionTracking.Value;
            }

            var now  = DateTime.UtcNow;
            var logs = RequestLogger.GetLatestLogs(request.Take).AsQueryable();

            if (request.BeforeSecs.HasValue)
            {
                logs = logs.Where(x => (now - x.DateTime) <= TimeSpan.FromSeconds(request.BeforeSecs.Value));
            }
            if (request.AfterSecs.HasValue)
            {
                logs = logs.Where(x => (now - x.DateTime) > TimeSpan.FromSeconds(request.AfterSecs.Value));
            }
            if (!request.IpAddress.IsNullOrEmpty())
            {
                logs = logs.Where(x => x.IpAddress == request.IpAddress);
            }
            if (!request.UserAuthId.IsNullOrEmpty())
            {
                logs = logs.Where(x => x.UserAuthId == request.UserAuthId);
            }
            if (!request.SessionId.IsNullOrEmpty())
            {
                logs = logs.Where(x => x.SessionId == request.SessionId);
            }
            if (!request.Referer.IsNullOrEmpty())
            {
                logs = logs.Where(x => x.Referer == request.Referer);
            }
            if (!request.PathInfo.IsNullOrEmpty())
            {
                logs = logs.Where(x => x.PathInfo == request.PathInfo);
            }
            if (!request.Ids.IsEmpty())
            {
                logs = logs.Where(x => request.Ids.Contains(x.Id));
            }
            if (request.BeforeId.HasValue)
            {
                logs = logs.Where(x => x.Id <= request.BeforeId);
            }
            if (request.AfterId.HasValue)
            {
                logs = logs.Where(x => x.Id > request.AfterId);
            }
            if (request.WithErrors.HasValue)
            {
                logs = request.WithErrors.Value
                    ? logs.Where(x => x.ErrorResponse != null)
                    : logs.Where(x => x.ErrorResponse == null);
            }
            if (request.DurationLongerThan.HasValue)
            {
                logs = logs.Where(x => x.RequestDuration > request.DurationLongerThan.Value);
            }
            if (request.DurationLessThan.HasValue)
            {
                logs = logs.Where(x => x.RequestDuration < request.DurationLessThan.Value);
            }

            var results = logs.Skip(request.Skip).OrderByDescending(x => x.Id).ToList();

            return(new RequestLogsResponse {
                Results = results,
                Usage = Usage,
            });
        }