diff --git a/Bootstrap.Admin/Content/css/admin.css b/Bootstrap.Admin/Content/css/admin.css
index 4bc5a440..c0a36fb4 100644
--- a/Bootstrap.Admin/Content/css/admin.css
+++ b/Bootstrap.Admin/Content/css/admin.css
@@ -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;
}
diff --git a/Bootstrap.Admin/Content/js/framework.js b/Bootstrap.Admin/Content/js/framework.js
index a142a46d..6f7cfa4f 100644
--- a/Bootstrap.Admin/Content/js/framework.js
+++ b/Bootstrap.Admin/Content/js/framework.js
@@ -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)) {
+ var formatData = result;
if ($.isArray(result)) {
- var formatData = 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('
', ele);
+ return $.format('', 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 } });
diff --git a/Bootstrap.Admin/Controllers/ExceptionsController.cs b/Bootstrap.Admin/Controllers/ExceptionsController.cs
index e2e431cf..e883353b 100644
--- a/Bootstrap.Admin/Controllers/ExceptionsController.cs
+++ b/Bootstrap.Admin/Controllers/ExceptionsController.cs
@@ -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
///
///
[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("<", "<").Replace(">", ">").Replace("\r\n", "") };
+ while (!reader.EndOfStream)
+ {
+ var line = reader.ReadLine().Replace("<", "<").Replace(">", ">");
+ if (line == "General Information ") sb.AppendFormat("{0}
", line);
+ else if (line.StartsWith("TimeStamp:")) sb.AppendFormat("{0}
", line);
+ else if (line.EndsWith("Exception Information")) sb.AppendFormat("{0}
", line);
+ else if (line.StartsWith("Message:")) sb.AppendFormat("{0}
", line);
+ else if (line.StartsWith("ErrorSql:")) sb.AppendFormat("{0}
", line);
+ else if (line.StartsWith("Exception Type: Longbow.Data.DBAccessException")) sb.AppendFormat("{0}
", line);
+ else if (line.StartsWith("StackTrace Information")) sb.AppendFormat("{0}
", line);
+ else sb.AppendFormat("{0}
", line);
+ };
}
+ return sb.ToString();
}
}
}
diff --git a/Bootstrap.Admin/Models/QueryExceptionOption.cs b/Bootstrap.Admin/Models/QueryExceptionOption.cs
index 5f1c276e..bf1776b2 100644
--- a/Bootstrap.Admin/Models/QueryExceptionOption.cs
+++ b/Bootstrap.Admin/Models/QueryExceptionOption.cs
@@ -11,11 +11,11 @@ namespace Bootstrap.Admin.Models
///
///
///
- public string OperateTimeStart { get; set; }
+ public DateTime StartTime { get; set; }
///
///
///
- public string OperateTimeEnd { get; set; }
+ public DateTime EndTime { get; set; }
///
///
///
@@ -23,45 +23,35 @@ namespace Bootstrap.Admin.Models
public QueryData RetrieveData()
{
var data = ExceptionHelper.RetrieveExceptions();
-
- if (!string.IsNullOrEmpty(OperateTimeStart))
- {
- DateTime opTimeStart = StringToDateTime(OperateTimeStart);
- if (opTimeStart != null)
- data = data.Where(t => IsSmallThen(opTimeStart, t.LogTime));
+ if (StartTime > DateTime.MinValue)
+ {
+ data = data.Where(t => t.LogTime > StartTime);
}
- if (!string.IsNullOrEmpty(OperateTimeEnd))
- {
- DateTime opTimeEnd = StringToDateTime(OperateTimeEnd);
- if (opTimeEnd != null)
- data = data.Where(t => IsSmallThen(t.LogTime, opTimeEnd));
+ if (EndTime > DateTime.MinValue)
+ {
+ data = data.Where(t => t.LogTime < EndTime);
}
-
var ret = new QueryData();
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;
- }
- ///
- /// 比较两个DateTime
- /// (去掉了毫秒)
- ///
- ///
- ///
- ///
- 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);
- }
}
}
diff --git a/Bootstrap.Admin/Scripts/Exceptions.js b/Bootstrap.Admin/Scripts/Exceptions.js
index 12f465bd..2c8fcde6 100644
--- a/Bootstrap.Admin/Scripts/Exceptions.js
+++ b/Bootstrap.Admin/Scripts/Exceptions.js
@@ -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('
');
Exceptions.getFileByName(fileName, function (data) {
- $dataFormDetail.html(data.content);
+ $dataFormDetail.html(data);
});
});
diff --git a/Bootstrap.Admin/Views/Admin/Exceptions.cshtml b/Bootstrap.Admin/Views/Admin/Exceptions.cshtml
index d206dcba..e9467f63 100644
--- a/Bootstrap.Admin/Views/Admin/Exceptions.cshtml
+++ b/Bootstrap.Admin/Views/Admin/Exceptions.cshtml
@@ -39,7 +39,7 @@