public ITraceLogData GetTraceLog(ITraceLogSearchParameter parameter, string path) { return LoadTraceLog(parameter, path); }
private ITraceLogData LoadTraceLog(ITraceLogSearchParameter parameter, string path) { DateTime startDate; DateTime endDate; try { startDate = DateTime.Parse(parameter.StartDate); endDate = DateTime.Parse(parameter.EndDate); } catch { return null; } TimeSpan startTime; TimeSpan endTime; if (TimeSpan.TryParse(parameter.StartTime, out startTime) == false) { return null; } if (TimeSpan.TryParse(parameter.EndTime, out endTime) == false) { return null; } DateTime now = DateTime.Now; startDate = new DateTime(startDate.Year, startDate.Month, startDate.Day, startTime.Hours, startTime.Minutes, 00); endDate = new DateTime(endDate.Year, endDate.Month, endDate.Day, endTime.Hours, endTime.Minutes, 59); List<string> lines = new List<string>(); for (DateTime date = startDate; date <= endDate; date = date.AddDays(1)) { int year = date.Year; string filename = path + year.ToString() + @"\" + date.ToString("MM") + @"\" + date.ToString(@"yyyy-MM-dd") + ".log"; string[] strs = DBUtility.LoadCSV(filename); if (strs != null) lines.AddRange(strs); } var query = from row in lines let x = row.Split(',') where x.Count() > 1 && IsInDateTime(x[0], startDate, endDate) select new TraceLogItem { Date = x[0], Message = SumTraceString(x) }; try { TraceLogData result = new TraceLogData(); result.Items = query.ToArray<ITraceLogItem>(); return result; } catch { return null; } }