public LogSearchResponse Get(LogSearchRequest request)
        {
            request = request ?? new LogSearchRequest();
            IFindFluent<BsonDocument, BsonDocument> cursor;
            if (!request.IsEmpty)
            {
                List<FilterDefinition<BsonDocument>> queries = new List<FilterDefinition<BsonDocument>>();
                
                if (!String.IsNullOrWhiteSpace(request.Query))
                {
                    var queryExpr = new BsonRegularExpression(new Regex(request.Query, RegexOptions.IgnoreCase));
                    queries.Add(Builders< BsonDocument>.Filter.Or(
                        Builders< BsonDocument>.Filter.Regex(FieldNames.Message, queryExpr),
                        Builders<BsonDocument>.Filter.Regex(FieldNames.Loggername, queryExpr)
                    ));
                }

                if (!String.IsNullOrWhiteSpace(request.Level))
                {
                    var levels = request.Level.Split(',').Select(x => x.Trim()).ToArray();
                    queries.Add(Builders<BsonDocument>.Filter.In(FieldNames.Level, levels.Select(BsonValue.Create)));
                }

               cursor = Logs.Find(Builders<BsonDocument>.Filter.And(queries));

            }
            else
            {
                cursor = Logs.Find(Builders<BsonDocument>.Filter.Empty);
            }

            var response = new LogSearchResponse
            {
                Items = cursor
                    .Sort(Builders<BsonDocument>.Sort.Descending(FieldNames.Timestamp))
                    .Skip(request.LogsPerPage*(request.Page - 1))
                    .Limit(request.LogsPerPage)
                    .ToList()
                    .Select(x => x.ToDictionary()),
                Count = cursor.Count()
            };

            return response;
        }
        public LogSearchResponse Get(LogSearchRequest request)
        {
            request = request ?? new LogSearchRequest();
            IFindFluent <BsonDocument, BsonDocument> cursor;

            if (!request.IsEmpty)
            {
                List <FilterDefinition <BsonDocument> > queries = new List <FilterDefinition <BsonDocument> >();

                if (!String.IsNullOrWhiteSpace(request.Query))
                {
                    var queryExpr = new BsonRegularExpression(new Regex(request.Query, RegexOptions.IgnoreCase));
                    queries.Add(Builders <BsonDocument> .Filter.Or(
                                    Builders <BsonDocument> .Filter.Regex(FieldNames.Message, queryExpr),
                                    Builders <BsonDocument> .Filter.Regex(FieldNames.Loggername, queryExpr)
                                    ));
                }

                if (!String.IsNullOrWhiteSpace(request.Level))
                {
                    var levels = request.Level.Split(',').Select(x => x.Trim()).ToArray();
                    queries.Add(Builders <BsonDocument> .Filter.In(FieldNames.Level, levels.Select(BsonValue.Create)));
                }

                cursor = Logs.Find(Builders <BsonDocument> .Filter.And(queries));
            }
            else
            {
                cursor = Logs.Find(Builders <BsonDocument> .Filter.Empty);
            }

            var response = new LogSearchResponse
            {
                Items = cursor
                        .Sort(Builders <BsonDocument> .Sort.Descending(FieldNames.Timestamp))
                        .Skip(request.LogsPerPage * (request.Page - 1))
                        .Limit(request.LogsPerPage)
                        .ToList()
                        .Select(x => x.ToDictionary()),
                Count = cursor.Count()
            };

            return(response);
        }