Beispiel #1
0
        public dynamic LogViewer()
        {
            long start = Convert.ToInt64(Request.Query["start"]);
            long end   = Convert.ToInt64(Request.Query["end"]);
            int  appId = Convert.ToInt32(Request.Query["appId"]);

            string level_str = Request.Query["level"];

            if (string.IsNullOrWhiteSpace(level_str))
            {
                level_str = "1,2,3,4";
            }
            List <int> level = new List <int>();

            level_str.Split(',').ToList().ForEach(x => level.Add(Convert.ToInt32(x)));

            string title    = Request.Query["title"];
            string msg      = Request.Query["msg"];
            string ip       = Request.Query["ip"];
            string source   = Request.Query["source"];
            int    limit    = Convert.ToInt32(Request.Query["limit"]);
            string tags_str = Request.Query["tags"];
            var    viewer   = LogViewerManager.GetLogViewer();

            var result = new LogVM();

            long ipNum = Utils.IPToNumber(ip);

            List <string> tags = new List <string>();

            if (!string.IsNullOrWhiteSpace(tags_str))
            {
                tags = tags_str.Split(',').Distinct().ToList();
            }

            var lst = viewer.GetLogs(start, end, appId, level.ToArray(), title, msg, source, ipNum, tags, limit);

            result.List  = lst;
            result.Start = start;
            result.End   = end;
            var last = lst.LastOrDefault();

            if (last != null)
            {
                result.Cursor = lst.Min(x => x.Time);
                long min = result.List.Min(x => x.Time);
                long max = result.List.Max(x => x.Time);

                long first = result.List.FirstOrDefault().Time;
                long lastt = result.List.LastOrDefault().Time;
            }
            var json_result = Newtonsoft.Json.JsonConvert.SerializeObject(result);

            return(json_result);
        }
Beispiel #2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            long start = Convert.ToInt64(context.Request["start"]);
            long end   = Convert.ToInt64(context.Request["end"]);
            int  appId = Convert.ToInt32(context.Request["appId"]);

            string level_str = context.Request["level"];

            if (string.IsNullOrWhiteSpace(level_str))
            {
                level_str = "1,2,3,4";
            }
            int[] level = Array.ConvertAll <string, int>(level_str.Split(','), x => Convert.ToInt32(x));

            string title    = context.Request["title"];
            string msg      = context.Request["msg"];
            string ip       = context.Request["ip"];
            string source   = context.Request["source"];
            int    limit    = Convert.ToInt32(context.Request["limit"]);
            string tags_str = context.Request["tags"];
            var    viewer   = LogViewerManager.GetLogViewer();

            var result = new LogVM();

            long ipNum = Utils.IPToNumber(ip);

            //long start_num = Utils.GetTimeStamp(start);

            //long end_num = Utils.GetTimeStamp(end);

            List <string> tags = new List <string>();

            if (!string.IsNullOrWhiteSpace(tags_str))
            {
                tags = tags_str.Split(',').Distinct().ToList();
            }

            //tags.Add("a=a");

            var lst = viewer.GetLogs(start, end, appId, level, title, msg, source, ipNum, tags, limit);

            result.List  = lst;
            result.Start = start;
            result.End   = end;
            var last = lst.LastOrDefault();

            if (last != null)
            {
                result.Cursor = lst.Min(x => x.Time);
                long min = result.List.Min(x => x.Time);
                long max = result.List.Max(x => x.Time);

                long first = result.List.FirstOrDefault().Time;
                long lastt = result.List.LastOrDefault().Time;
            }
            var json_result = Newtonsoft.Json.JsonConvert.SerializeObject(result);

            context.Response.AddHeader("Access-Control-Allow-Origin", "*");//允许跨域请求

            context.Response.Write(json_result);
        }