コード例 #1
0
        public Tuple <bool, T> GetAppLogsPage <T>(PageAppLog appLog)
        {
            Dictionary <string, object> paramDic = appLog.ToDictionary();
            var action = "GetAppLogsPage";

            return(DoPost <T>(SNAKE_WEBAPI_TRACKLOG_CONTROLLER, action, paramDic));
        }
コード例 #2
0
 public Task <Tuple <bool, T> > GetAppLogsPageAsync <T>(PageAppLog appLog)
 {
     return(Task.Run(() => GetAppLogsPage <T>(appLog)));
 }
コード例 #3
0
        public TransData <IList <AppLog> > GetAppLogsPage([FromBody] PageAppLog pageAppLog)
        {
            var result = new TransData <IList <AppLog> >();

            if (pageAppLog == null)
            {
                return(Response <IList <AppLog> >(null, "Parameter is null", (int)ServiceResultCode.ParameterError));
            }
            if (pageAppLog.PageIndex <= 0 || pageAppLog.PageSize <= 0)
            {
                return(Response <IList <AppLog> >(null, "Page param is null", (int)ServiceResultCode.ParameterError));
            }
            if (pageAppLog.CTime == null || pageAppLog.CTimeEnd == null)
            {
                return(Response <IList <AppLog> >(null, "CTime is null", (int)ServiceResultCode.ParameterError));
            }

            try
            {
                var repository = MongoRepository <AppLog> .Instance;
                var list       = new List <FilterDefinition <AppLog> >();
                list.Add(Builders <AppLog> .Filter.Gt(x => x.CTime, pageAppLog.CTime));
                list.Add(Builders <AppLog> .Filter.Lt(x => x.CTime, pageAppLog.CTimeEnd));

                if (!string.IsNullOrEmpty(pageAppLog.Application))
                {
                    list.Add(Builders <AppLog> .Filter.Eq(x => x.Application, pageAppLog.Application));
                }
                if (!string.IsNullOrEmpty(pageAppLog.IPv4))
                {
                    list.Add(Builders <AppLog> .Filter.Eq(x => x.IPv4, pageAppLog.IPv4));
                }
                if (!string.IsNullOrEmpty(pageAppLog.Machine))
                {
                    list.Add(Builders <AppLog> .Filter.Eq(x => x.Machine, pageAppLog.Machine));
                }
                if (!string.IsNullOrEmpty(pageAppLog.LogCategory))
                {
                    list.Add(Builders <AppLog> .Filter.Eq(x => x.LogCategory, pageAppLog.LogCategory));
                }
                if (pageAppLog.Level >= 1)
                {
                    list.Add(Builders <AppLog> .Filter.Eq(x => x.Level, pageAppLog.Level));
                }
                if (!string.IsNullOrEmpty(pageAppLog.Message))
                {
                    //list.Add(Builders<AppLog>.Filter.Text(appLog.Message));  //大量消耗内存,慎用
                    list.Add(Builders <AppLog> .Filter.Eq("Message", pageAppLog.Message));
                }
                if (pageAppLog.Tags != null && pageAppLog.Tags.Count > 0)
                {
                    list.Add(Builders <AppLog> .Filter.All(x => x.Tags, pageAppLog.Tags));
                }
                FilterDefinition <AppLog> filter = Builders <AppLog> .Filter.And(list);

                var sort = Builders <AppLog> .Sort.Descending(x => x.CTime);

                result.Data = repository.GetPageOrderBy(filter, sort, new QueryParams()
                {
                    Index = pageAppLog.PageIndex, Size = pageAppLog.PageSize
                });
                result.Code = (int)ServiceResultCode.Succeeded;
            }
            catch (Exception e)
            {
                result.Data    = null;
                result.Message = "服务异常!";
                result.Code    = (int)ServiceResultCode.UndefinedError;
            }
            return(result);
        }