/// <summary> /// Save Logs /// </summary> protected void SaveBtn_Click(object sender, DirectEventArgs e) { try { var rowsCnt = 0; var fromTime = DateTime.Parse(FromDate.Text); var toTime = DateTime.Parse(ToDate.Text); var _operator = UserData.Uid; string[] eventLevel = null; string[] eventType = null; if (LogLevelMultiCombo.SelectedItems.Count > 0) { eventLevel = new string[LogLevelMultiCombo.SelectedItems.Count]; for (int i = 0; i < eventLevel.Length; i++) { eventLevel[i] = LogLevelMultiCombo.SelectedItems[i].Value; } } if (LogTypeMultiCombo.SelectedItems.Count > 0) { eventType = new string[LogTypeMultiCombo.SelectedItems.Count]; for (int i = 0; i < eventType.Length; i++) { eventType[i] = LogTypeMultiCombo.SelectedItems[i].Value; } } var logEntity = new BLog(); var logs = logEntity.GetSysLogs(fromTime, toTime, eventLevel, eventType, _operator, 1, Int32.MaxValue, ref rowsCnt); var logText = new StringBuilder(); logText.AppendLine("动力环境监控中心系统Web日志"); logText.AppendLine(); foreach (var log in logs) { logText.AppendLine("======================================================================================="); logText.AppendLine(String.Format("事件编号: {0}", log.EventID)); logText.AppendLine(String.Format("事件时间: {0}", WebUtility.GetDateString(log.EventTime))); logText.AppendLine(String.Format("事件级别: {0}", WebUtility.GetSysLogLevelName(log.EventLevel))); logText.AppendLine(String.Format("事件类型: {0}", WebUtility.GetSysLogTypeName(log.EventType))); logText.AppendLine(String.Format("请求路径: {0}", log.Url)); logText.AppendLine(String.Format("客户端IP: {0}", log.ClientIP)); logText.AppendLine(String.Format("触发源: {0}", log.Operator)); logText.AppendLine(String.Format("事件信息: {0}", WebUtility.JsonCharFilter(log.Message))); logText.AppendLine(); } HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Charset = "UTF-8"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; HttpContext.Current.Response.ContentType = "application/ms-txt"; HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=SysLog.txt"); var tw = HttpContext.Current.Response.Output; tw.Write(logText.ToString()); HttpContext.Current.Response.End(); } catch (Exception err) { WebUtility.WriteLog(EnmSysLogLevel.Error, EnmSysLogType.Exception, err.ToString(), Page.User.Identity.Name); WebUtility.ShowMessage(EnmErrType.Error, err.Message); } }
/// <summary> /// Log Grid Refresh /// </summary> protected void OnLogGridRefresh(object sender, StoreRefreshDataEventArgs e) { try { var start = Int32.Parse(e.Parameters["start"]); var limit = Int32.Parse(e.Parameters["limit"]); var data = new List <object>(limit); var rowsCnt = 0; var fromTime = DateTime.Parse(FromDate.Text); var toTime = DateTime.Parse(ToDate.Text); string[] eventLevel = null; string[] eventType = null; if (LogLevelMultiCombo.SelectedItems.Count > 0) { eventLevel = new string[LogLevelMultiCombo.SelectedItems.Count]; for (int i = 0; i < eventLevel.Length; i++) { eventLevel[i] = LogLevelMultiCombo.SelectedItems[i].Value; } } if (LogTypeMultiCombo.SelectedItems.Count > 0) { eventType = new string[LogTypeMultiCombo.SelectedItems.Count]; for (int i = 0; i < eventType.Length; i++) { eventType[i] = LogTypeMultiCombo.SelectedItems[i].Value; } } var logEntity = new BLog(); var logs = logEntity.GetSysLogs(fromTime, toTime, eventLevel, eventType, null, start + 1, start + limit, ref rowsCnt); foreach (var log in logs) { data.Add(new { EventID = log.EventID, EventTime = WebUtility.GetDateString(log.EventTime), EventLevel = WebUtility.GetSysLogLevelName(log.EventLevel), EventType = WebUtility.GetSysLogTypeName(log.EventType), Message = WebUtility.JsonCharFilter(log.Message), Url = log.Url, ClientIP = log.ClientIP, Operator = log.Operator }); } e.Total = rowsCnt; LogGridStore.DataSource = data; LogGridStore.DataBind(); } catch (Exception err) { WebUtility.WriteLog(EnmSysLogLevel.Error, EnmSysLogType.Exception, err.ToString(), Page.User.Identity.Name); WebUtility.ShowMessage(EnmErrType.Error, err.Message); } }