/// <summary> /// 获取轨迹日志(具体实现) /// </summary> /// <param name="input"></param> /// <returns></returns> public GetLogTraceOutput GetLogTraces(GetLogTraceInput input) { var query = GetLogTracesQuery(input); GetLogTraceOutput getLogTraceOutput = new GetLogTraceOutput(); var totalCount = query.Count(); input.Sorting = input.Sorting.Replace("SysName", "SystemID").Replace("LogTypeCN", "LogType"); var list = query.OrderBy(input.Sorting).PageBy(input).ToList(); var listDtos = list.MapTo <List <Log_OperateTraceDto> >(); getLogTraceOutput.Items = listDtos; getLogTraceOutput.TotalCount = totalCount; getLogTraceOutput = GetCategorySummary(input.StartT.ToShortDateString(), input.EndT.ToShortDateString(), input, getLogTraceOutput); return(getLogTraceOutput); }
//获取轨迹日志数据 public ActionResult GetLogTraceData(TraceSearchVM para) { GetLogTraceInput traceIn = new GetLogTraceInput() { MaxResultCount = para.limit, SkipCount = para.offset, Sorting = para.sortby, IsDesc = para.sortway == "asc" ? false : true, StartT = string.IsNullOrEmpty(para.from) ? new DateTime() : Convert.ToDateTime(para.from), EndT = string.IsNullOrEmpty(para.to) ? new DateTime() : Convert.ToDateTime(para.to).AddDays(1), Express = null, LogType = para.type, ServerHost = para.host, ServerIP = "", SystemID = new List <SysCategory>() { para.app }, KeyWord = !string.IsNullOrEmpty(para.keyWord) ? para.keyWord.Trim() : "", UserName = !string.IsNullOrEmpty(para.userName) ? para.userName.Trim() : "", ModuTable = !string.IsNullOrEmpty(para.modTab) ? para.modTab.Trim() : "", }; GetLogTraceOutput traces = _logTraceService.GetLogTraces(traceIn); try { traces.Items = traces.Items.Select(a => { a.ClientHost = a.ClientHost.Replace(".LgWG.com", ""); return(a); }).ToList(); } catch { } var resultItems = traces.Items.MapTo <List <Log_OperateTraceView> >(); var errLogNum = 8; var json = AbpJson(new { total = traces.TotalCount, rows = resultItems, ErrLogNum = traces.ErrLogNum, NameDatas = traces.NameDatas }, null, null, JsonRequestBehavior.AllowGet, true, false); return(json); }
//获取按服务器,系统、日志类型、用户分类的信息 GetLogTraceOutput GetCategorySummary(string startT, string endT, GetLogTraceInput input, GetLogTraceOutput getLogTraceOutput) { var query = (from d in GetLogTracesQuery(input) select new { ServerHost = d.ServerHost, SystemID = d.SystemID, LogType = d.LogType, UserName = string.IsNullOrEmpty(d.UserName) ? "系统" : d.UserName }).ToList(); getLogTraceOutput.ErrLogNum = query.Where(a => a.LogType == Log2Net.Models.LogType.异常).Count(); var serversGroup = query.GroupBy(a => a.ServerHost); Dictionary <string, int> dicServer = new Dictionary <string, int>(); foreach (var item in serversGroup) { dicServer.Add(item.Key, item.Count()); } NameData serverND = new NameData() { Title = "各服务器的情况", Name = dicServer.Keys.ToArray(), Data = dicServer.Values.ToArray() }; var sysidsGroup = query.GroupBy(a => a.SystemID); Dictionary <string, int> dicSys = new Dictionary <string, int>(); foreach (var item in sysidsGroup) { dicSys.Add(Configuration.SysNameMap.GetMySystemName(item.Key), item.Count()); } NameData sysidND = new NameData() { Title = "各网站的情况", Name = dicSys.Keys.ToArray(), Data = dicSys.Values.ToArray() }; var logTypesGroup = query.GroupBy(a => a.LogType); Dictionary <string, int> dicLogType = new Dictionary <string, int>(); foreach (var item in logTypesGroup) { dicLogType.Add(item.Key.ToString(), item.Count()); } NameData logTypeND = new NameData() { Title = "各日志类型的情况", Name = dicLogType.Keys.ToArray(), Data = dicLogType.Values.ToArray() }; var usersGroup = query.GroupBy(a => a.UserName); Dictionary <string, int> dicUser = new Dictionary <string, int>(); foreach (var item in usersGroup) { dicUser.Add(item.Key, item.Count()); } NameData userND = new NameData() { Title = "各用户的情况", Name = dicUser.Keys.ToArray(), Data = dicUser.Values.ToArray() }; List <NameData> nameDatas = new List <NameData>() { serverND, sysidND, logTypeND, userND }; getLogTraceOutput.NameDatas = nameDatas; return(getLogTraceOutput); }