修改BUG:修复程序异常页面查询、排序功能,完善查看服务器日志格式化文件流

This commit is contained in:
Argo-Lenovo 2016-11-17 21:36:02 +08:00
parent 2bdc2603c4
commit 8bab03dbb9
6 changed files with 90 additions and 54 deletions

View File

@ -1,4 +1,31 @@
.hidden-tb {
.logfile {
color: #d41404;
}
.logfile:focus, .logfile:active, .logfile:hover {
color: red;
}
.logfile span {
margin-left: 4px;
}
.logTs, .logSql, .logDbExcep {
color: red;
font-weight: 600;
}
.logExcep {
color: #337ab7;
font-weight: 600;
}
.logMsg {
color: #ce2520;
font-weight: 600;
}
.hidden-tb {
margin-left: 6px;
}

View File

@ -37,7 +37,7 @@
// handler modal window show event
if (this.options.modal && this.options.modal.constructor === String) {
$('#' + this.options.modal).on('show.bs.modal', function (e) {
if (that.options.validateForm.constructor === String) {
if (that.options.validateForm && that.options.validateForm.constructor === String) {
var v = $('#' + that.options.validateForm);
var vf = v.validate();
vf.currentElements.each(function () { $(this).popover('destroy'); })
@ -274,12 +274,11 @@
function success(result) {
if ($.isFunction(data.callback)) {
if ($.isArray(result)) {
var formatData = result;
if ($.isArray(result)) {
if ($.isFunction(data.html)) formatData = data.html(result);
data.callback(formatData);
return;
}
data.callback(formatData);
}
else if ($.isPlainObject(data.callback) && data.callback.modal !== undefined) {
$("#" + data.callback.modal).modal('hide');
@ -288,7 +287,6 @@
if (result) { swal("成功", data.title, "success"); }
else { swal("失败", data.title, "error"); }
}
if ($.isFunction(data.callback)) data.callback(result);
}
}
// Roles
@ -420,12 +418,12 @@
title: "程序异常日志",
html: function (result) {
return result.map(function (ele) {
return $.format('<div class="form-group col-lg-3 col-md-3 col-sm-4 col-xs-6"><a href="#">{0}</a></div>', ele);
return $.format('<div class="form-group col-lg-3 col-md-3 col-sm-4 col-xs-6"><a class="logfile" href="#"><i class="fa fa-file-text-o"></i><span>{0}</span></a></div>', ele);
}).join('');
}
}
Exceptions.getFiles = function (callback) {
processData.call(this, { Id: "", callback: callback });
processData.call(this, { Id: "", callback: callback, swal: false });
}
Exceptions.getFileByName = function (fileName, callback) {
processData.call(this, { Id: "", callback: callback, method: "PUT", swal: false, data: { "": fileName } });

View File

@ -3,6 +3,7 @@ using Bootstrap.DataAccess;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Http;
@ -37,14 +38,27 @@ namespace Bootstrap.Admin.Controllers
/// </summary>
/// <returns></returns>
[HttpPut]
public dynamic Put([FromBody]string fileName)
public string Put([FromBody]string fileName)
{
var logName = HttpContext.Current.Server.MapPath(string.Format("~/App_Data/ErrorLog/{0}.log", fileName));
if (!File.Exists(logName)) return new { content = string.Empty };
if (!File.Exists(logName)) return "无此日志文件";
StringBuilder sb = new StringBuilder();
using (StreamReader reader = new StreamReader(logName))
{
return new { content = reader.ReadToEnd().Replace("<", "&lt;").Replace(">", "&gt;").Replace("\r\n", "</br>") };
while (!reader.EndOfStream)
{
var line = reader.ReadLine().Replace("<", "&lt;").Replace(">", "&gt;");
if (line == "General Information ") sb.AppendFormat("<h4><b>{0}</b></h4>", line);
else if (line.StartsWith("TimeStamp:")) sb.AppendFormat("<div class='logTs'>{0}</div>", line);
else if (line.EndsWith("Exception Information")) sb.AppendFormat("<div class='logExcep'>{0}</div>", line);
else if (line.StartsWith("Message:")) sb.AppendFormat("<div class='logMsg'>{0}</div>", line);
else if (line.StartsWith("ErrorSql:")) sb.AppendFormat("<div class='logSql'>{0}</div>", line);
else if (line.StartsWith("Exception Type: Longbow.Data.DBAccessException")) sb.AppendFormat("<div class='logDbExcep'>{0}</div>", line);
else if (line.StartsWith("StackTrace Information")) sb.AppendFormat("<b>{0}</b><br>", line);
else sb.AppendFormat("{0}<br>", line);
};
}
return sb.ToString();
}
}
}

View File

@ -11,11 +11,11 @@ namespace Bootstrap.Admin.Models
/// <summary>
///
/// </summary>
public string OperateTimeStart { get; set; }
public DateTime StartTime { get; set; }
/// <summary>
///
/// </summary>
public string OperateTimeEnd { get; set; }
public DateTime EndTime { get; set; }
/// <summary>
///
/// </summary>
@ -23,45 +23,35 @@ namespace Bootstrap.Admin.Models
public QueryData<Exceptions> RetrieveData()
{
var data = ExceptionHelper.RetrieveExceptions();
if (!string.IsNullOrEmpty(OperateTimeStart))
if (StartTime > DateTime.MinValue)
{
DateTime opTimeStart = StringToDateTime(OperateTimeStart);
if (opTimeStart != null)
data = data.Where(t => IsSmallThen(opTimeStart, t.LogTime));
data = data.Where(t => t.LogTime > StartTime);
}
if (!string.IsNullOrEmpty(OperateTimeEnd))
if (EndTime > DateTime.MinValue)
{
DateTime opTimeEnd = StringToDateTime(OperateTimeEnd);
if (opTimeEnd != null)
data = data.Where(t => IsSmallThen(t.LogTime, opTimeEnd));
data = data.Where(t => t.LogTime < EndTime);
}
var ret = new QueryData<Exceptions>();
ret.total = data.Count();
data = Order == "asc" ? data.OrderBy(t => t.AppDomainName) : data.OrderByDescending(t => t.AppDomainName);
switch (Sort)
{
case "ErrorPage":
data = Order == "asc" ? data.OrderBy(t => t.ErrorPage) : data.OrderByDescending(t => t.ErrorPage);
break;
case "UserID":
data = Order == "asc" ? data.OrderBy(t => t.UserID) : data.OrderByDescending(t => t.UserID);
break;
case "UserIp":
data = Order == "asc" ? data.OrderBy(t => t.UserIp) : data.OrderByDescending(t => t.UserIp);
break;
case "LogTime":
data = Order == "asc" ? data.OrderBy(t => t.LogTime) : data.OrderByDescending(t => t.LogTime);
break;
default:
break;
}
ret.rows = data.Skip(Offset).Take(Limit);
return ret;
}
private static DateTime StringToDateTime(string dt_str)
{
DateTime dt;
DateTimeFormatInfo dtFormat = new DateTimeFormatInfo();
dtFormat.ShortDatePattern = "yyyy-MM-dd HH:mm:ss";
dt = Convert.ToDateTime(dt_str, dtFormat);
return dt;
}
/// <summary>
/// 比较两个DateTime
/// (去掉了毫秒)
/// </summary>
/// <param name="d1"></param>
/// <param name="d2"></param>
/// <returns></returns>
private static bool IsSmallThen(DateTime d1, DateTime d2)
{
return new DateTime(d1.Year, d1.Month, d1.Day, d1.Hour, d1.Minute, d1.Second) <=
new DateTime(d2.Year, d2.Month, d2.Day, d2.Hour, d2.Minute, d2.Second);
}
}
}

View File

@ -1,4 +1,5 @@
$(function () {
var url = '../api/Exceptions/';
var $dialog = $('#dialogNew');
var $dataForm = $('#dataForm');
var $dataFormDetail = $('#dataFormDetail');
@ -6,14 +7,20 @@
var $errorDetail = $('#errorDetail');
var $errorDetailTitle = $('#myDetailModalLabel');
var bsa = new BootstrapAdmin({
url: url,
bootstrapTable: null,
validateForm: null
});
$('table').smartTable({
url: '../api/Exceptions',
url: url,
sortName: 'LogTime',
queryParams: function (params) { return $.extend(params, { OperateTimeStart: $("#txt_operate_start").val(), OperateTimeEnd: $("#txt_operate_end").val() }); },
queryParams: function (params) { return $.extend(params, { StartTime: $("#txt_operate_start").val(), EndTime: $("#txt_operate_end").val() }); },
columns: [{ checkbox: true },
{ title: "请求网址", field: "ErrorPage", sortable: false },
{ title: "用户名", field: "UserID", sortable: false },
{ title: "IP", field: "UserIp", sortable: false },
{ title: "请求网址", field: "ErrorPage", sortable: true },
{ title: "用户名", field: "UserID", sortable: true },
{ title: "IP", field: "UserIp", sortable: true },
{ title: "错误", field: "Message", sortable: false },
{ title: "记录时间", field: "LogTime", sortable: true }
]
@ -32,13 +39,13 @@
});
$dialog.on('click', 'a', function () {
var fileName = $(this).text();
var fileName = $(this).find('span').text();
$errorDetailTitle.text(fileName);
$errorList.hide();
$errorDetail.show();
$dataFormDetail.html('<div class="text-center"><i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i></div>');
Exceptions.getFileByName(fileName, function (data) {
$dataFormDetail.html(data.content);
$dataFormDetail.html(data);
});
});

View File

@ -39,7 +39,7 @@
<div class="form-group col-xs-12 col-sm-6 col-md-5 col-lg-5">
<label class="control-label" for="txt_operate_end">终止时间</label>
<div class="input-group input-append date form_datetime">
<input type="datetime" class="form-control" id="txt_operate_start" />
<input type="datetime" class="form-control" id="txt_operate_end" />
<span class="input-group-btn">
<button class="btn btn-default" type="button"><i class="fa fa-calendar" aria-hidden="true"></i></button>
</span>