Example #1
0
        public async Task <IResultList <LogEntry> > QueryAsync(string appId, LogQuery query, CancellationToken ct)
        {
            var filters = new List <FilterDefinition <MongoDbLogEntry> >
            {
                Filter.Eq(x => x.Entry.AppId, appId)
            };

            if (!string.IsNullOrWhiteSpace(query.Query))
            {
                var regex = new BsonRegularExpression(query.Query, "i");

                filters.Add(Filter.Regex(x => x.Entry.Message, regex));
            }

            var filter = Filter.And(filters);

            var resultItems = await Collection.Find(filter).ToListAsync(query, ct);

            var resultTotal = (long)resultItems.Count;

            if (query.ShouldQueryTotal(resultItems))
            {
                resultTotal = await Collection.Find(filter).CountDocumentsAsync(ct);
            }

            return(ResultList.Create(resultTotal, resultItems.Select(x => x.ToEntry())));
        }
Example #2
0
        public async Task <IResultList <LogEntry> > QueryAsync(string appId, LogQuery query,
                                                               CancellationToken ct = default)
        {
            using (var activity = Telemetry.Activities.StartActivity("MongoDbLogRepository/DeleteAsync"))
            {
                var filter = BuildFilter(appId, query);

                var resultItems = await Collection.Find(filter).SortByDescending(x => x.Entry.LastSeen).ToListAsync(query, ct);

                var resultTotal = (long)resultItems.Count;

                if (query.ShouldQueryTotal(resultItems))
                {
                    resultTotal = await Collection.Find(filter).CountDocumentsAsync(ct);
                }

                activity?.SetTag("numResults", resultItems.Count);
                activity?.SetTag("numTotal", resultTotal);

                return(ResultList.Create(resultTotal, resultItems.Select(x => x.ToEntry())));
            }
        }