/// <summary>Anies the given request.</summary> /// /// <exception cref="Exception">Thrown when an exception error condition occurs.</exception> /// /// <param name="request">The request.</param> /// /// <returns>An object.</returns> public object Any(RequestLogs request) { if (RequestLogger == null) { throw new Exception("No IRequestLogger is registered"); } RequiredRoleAttribute.AssertRequiredRoles(RequestContext, 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, }); }
/// <summary>Anies the given request.</summary> /// /// <exception cref="Exception">Thrown when an exception error condition occurs.</exception> /// /// <param name="request">The request.</param> /// /// <returns>An object.</returns> public object Any(RequestLogs request) { if (RequestLogger == null) throw new Exception("No IRequestLogger is registered"); RequiredRoleAttribute.AssertRequiredRoles(RequestContext, 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, }; }