diff --git a/Bootstrap.Admin/App_Data/ErrorLog/Readme.txt b/Bootstrap.Admin/App_Data/ErrorLog/Readme.txt new file mode 100644 index 00000000..a9148b07 --- /dev/null +++ b/Bootstrap.Admin/App_Data/ErrorLog/Readme.txt @@ -0,0 +1 @@ +请不要删除此目录 \ No newline at end of file diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index 884dd702..ee9fefc7 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -101,6 +101,7 @@ + @@ -294,7 +295,6 @@ - @@ -304,9 +304,7 @@ Web.config - - - + {af16ca71-b8c6-4f51-b38c-0c0300fdebd7} diff --git a/Bootstrap.Admin/Content/css/fa.css b/Bootstrap.Admin/Content/css/fa.css index 73e11629..f075dcf9 100644 --- a/Bootstrap.Admin/Content/css/fa.css +++ b/Bootstrap.Admin/Content/css/fa.css @@ -96,7 +96,7 @@ right: 16px; top: 62px; bottom: 80px; - overflow-y: scroll; + overflow: auto; } .icon-content .modal-footer { diff --git a/Bootstrap.Admin/Content/js/framework.js b/Bootstrap.Admin/Content/js/framework.js index b8b97ba2..dba25f11 100644 --- a/Bootstrap.Admin/Content/js/framework.js +++ b/Bootstrap.Admin/Content/js/framework.js @@ -246,7 +246,7 @@ var htmlTemplate = '
'; var processData = function (options) { - var data = $.extend({ data: { type: "" }, remote: true, method: "POST", Id: "", url: this.url, title: this.title, html: this.html }, options); + var data = $.extend({ data: { type: "" }, remote: true, method: "POST", Id: "", url: this.url, title: this.title, html: this.html, swal: true }, options); if (data.remote) { $.ajax({ @@ -275,14 +275,14 @@ else if ($.isPlainObject(data.callback) && data.callback.modal !== undefined) { $("#" + data.callback.modal).modal('hide'); } - if (data.remote) { + if (data.swal) { if (result) { swal("成功", data.title, "success"); } else { swal("失败", data.title, "error"); } } if ($.isFunction(data.callback)) data.callback(result); } } - // Role + // Roles Role = { url: '../api/Roles/', title: "授权角色", @@ -354,7 +354,8 @@ Group.saveGroupsByRoleId = function (roleId, groupIds, callback) { processData.call(this, { Id: roleId, callback: callback, method: "PUT", data: { type: "role", groupIds: groupIds } }); }; - //Menus + + // Menus Menu = { url: '../api/Menus/', title: "授权菜单", @@ -387,6 +388,7 @@ Menu.saveMenusByRoleId = function (roleId, menuIds, callback) { processData.call(this, { Id: roleId, callback: callback, method: "PUT", data: { type: "role", menuIds: menuIds } }); }; + //Profiles Profiles = { url: '../api/Profiles/', @@ -395,4 +397,21 @@ Profiles.saveWebSite = function (options) { processData.call(this, { data: options }); } + + // Exceptions + Exceptions = { + url: '../api/Exceptions/', + title: "程序异常日志", + html: function (result) { + return result.map(function (ele) { + return $.format('', ele); + }).join(''); + } + } + Exceptions.getFiles = function (callback) { + processData.call(this, { Id: "", callback: callback }); + } + Exceptions.getFileByName = function (fileName, callback) { + processData.call(this, { Id: "", callback: callback, method: "PUT", swal: false, data: { "": fileName } }); + } })(jQuery); \ No newline at end of file diff --git a/Bootstrap.Admin/Controllers/AdminController.cs b/Bootstrap.Admin/Controllers/AdminController.cs index bcb1d69f..f8237bcf 100644 --- a/Bootstrap.Admin/Controllers/AdminController.cs +++ b/Bootstrap.Admin/Controllers/AdminController.cs @@ -113,18 +113,6 @@ namespace Bootstrap.Admin.Controllers /// /// /// - public ActionResult Excep() - { - using (System.IO.StreamReader reader = new System.IO.StreamReader(Server.MapPath("~/App_Data/ErrorLog/Error2016-11-11.log"))) - { - ViewBag.Content = new MvcHtmlString(reader.ReadToEnd().Replace("\r\n", "
")); - } - return View(); - } - /// - /// - /// - /// public ActionResult Exceptions() { var v = new NavigatorBarModel("~/Admin/Exceptions"); diff --git a/Bootstrap.Admin/Controllers/ExceptionsController.cs b/Bootstrap.Admin/Controllers/ExceptionsController.cs index 17fb1072..44808592 100644 --- a/Bootstrap.Admin/Controllers/ExceptionsController.cs +++ b/Bootstrap.Admin/Controllers/ExceptionsController.cs @@ -1,20 +1,48 @@ -using Bootstrap.Admin.Models; -using Bootstrap.DataAccess; -using System.Web.Http; - -namespace Bootstrap.Admin.Controllers -{ - public class ExceptionsController : ApiController - { - /// - /// 显示所有异常 - /// - /// - /// - [HttpGet] - public QueryData Get([FromUri]QueryExceptionOption value) - { - return value.RetrieveData(); - } - } -} +using Bootstrap.Admin.Models; +using Bootstrap.DataAccess; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Web; +using System.Web.Http; + +namespace Bootstrap.Admin.Controllers +{ + public class ExceptionsController : ApiController + { + /// + /// 显示所有异常 + /// + /// + /// + [HttpGet] + public QueryData Get([FromUri]QueryExceptionOption value) + { + return value.RetrieveData(); + } + /// + /// + /// + /// + [HttpPost] + public IEnumerable Post() + { + var filePath = HttpContext.Current.Server.MapPath("~/App_Data/ErrorLog"); + return Directory.GetFiles(filePath).Select(f => Path.GetFileNameWithoutExtension(f)).OrderByDescending(s => s); + } + /// + /// + /// + /// + [HttpPut] + public dynamic 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 }; + using (StreamReader reader = new StreamReader(logName)) + { + return new { content = reader.ReadToEnd().Replace("\r\n", "
") }; + } + } + } +} diff --git a/Bootstrap.Admin/Scripts/Exceptions.js b/Bootstrap.Admin/Scripts/Exceptions.js index 13ed1042..7fbd0352 100644 --- a/Bootstrap.Admin/Scripts/Exceptions.js +++ b/Bootstrap.Admin/Scripts/Exceptions.js @@ -1,42 +1,53 @@ -$(function () { - var bsa = new BootstrapAdmin({ - url: '../api/Exceptions', - dataEntity: new DataEntity({ - map: { - ID: "ID", - AppDomainName: "appDomainName", - ErrorPage: "errorPage", - UserID: "userId", - UserIp: "userIp", - Message: "message", - StackTrace: "stackTrace", - LogTime:"logTime" - } - }), - }) - $('table').smartTable({ - url: '../api/Exceptions', //请求后台的URL(*) - sortName: 'AppDomainName', - queryParams: function (params) { return $.extend(params, { OperateTimeStart: $("#txt_operate_start").val(), OperateTimeEnd: $("#txt_operate_end").val() }); }, //传递参数(*) - columns: [{ checkbox: true }, - { title: "APP域名", field: "AppDomainName", sortable: true }, - { title: "错误页", field: "ErrorPage", sortable: false }, - { - title: "用户名", field: "UserID", sortable: false, - }, - { title: "用户IP", field: "UserIp", sortable: false }, - { title: "备注", field: "Message", sortable: false }, - { title: "栈记录", field: "StackTrace", sortable: false }, - { title: "异常捕获时间", field: "LogTime", sortable: false, - formatter: function (value, row, index) { - return value.substring(0, 19).replace("T", " "); - } - } - ] - }); - - $('input[type="datetime"]').parent().datetimepicker({ - locale: "zh-cn", - format: "YYYY-MM-DD" - }); +$(function () { + var $dialog = $('#dialogNew'); + var $dataForm = $('#dataForm'); + var $dataFormDetail = $('#dataFormDetail'); + var $errorList = $('#errorList'); + var $errorDetail = $('#errorDetail'); + var $errorDetailTitle = $('#myDetailModalLabel'); + + $('table').smartTable({ + url: '../api/Exceptions', + sortName: 'ErrorPage', + queryParams: function (params) { return $.extend(params, { OperateTimeStart: $("#txt_operate_start").val(), OperateTimeEnd: $("#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: "Message", sortable: false }, + { + title: "异常捕获时间", field: "LogTime", sortable: true, formatter: function (value, row, index) { + return new Date(value).format("yyyy-MM-dd HH:mm:ss"); + } + } + ] + }); + + $('input[type="datetime"]').parent().datetimepicker({ + locale: "zh-cn", + format: "YYYY-MM-DD" + }); + + $('#btn_view').on('click', function (row) { + Exceptions.getFiles(function (data) { + $dataForm.children('div').html(data); + }); + $dialog.modal('show'); + }); + + $dialog.on('click', 'a', function () { + var fileName = $(this).text(); + $errorDetailTitle.text(fileName); + $errorList.hide(); + $errorDetail.show(); + $dataFormDetail.html('
'); + Exceptions.getFileByName(fileName, function (data) { + $dataFormDetail.html(data.content); + }); + }); + + $errorDetail.on('click', 'button', function () { + $errorDetail.hide(); + $errorList.show(); + }); }); \ No newline at end of file diff --git a/Bootstrap.Admin/Views/Admin/Excep.cshtml b/Bootstrap.Admin/Views/Admin/Excep.cshtml deleted file mode 100644 index f58e7783..00000000 --- a/Bootstrap.Admin/Views/Admin/Excep.cshtml +++ /dev/null @@ -1,5 +0,0 @@ -@{ - ViewBag.Title = "Excep"; - Layout = "~/Views/Shared/_Layout.cshtml"; -} -
@ViewBag.Content
\ No newline at end of file diff --git a/Bootstrap.Admin/Views/Admin/Exceptions.cshtml b/Bootstrap.Admin/Views/Admin/Exceptions.cshtml index 89ecbda4..c86810b8 100644 --- a/Bootstrap.Admin/Views/Admin/Exceptions.cshtml +++ b/Bootstrap.Admin/Views/Admin/Exceptions.cshtml @@ -1,62 +1,108 @@ -@model NavigatorBarModel -@{ - ViewBag.Title = "程序异常"; - Layout = "~/Views/Shared/_Admin.cshtml"; -} -@section css { - - -} -@section Javascript { - - - - - - -} -@section header { - @Html.Partial("Header", Model) -} -@section navigator { - @Html.Partial("Navigator", Model) -} -
-
查询条件
-
-
-
-
- -
- - - - -
-
-
- -
- - - - -
-
-
- - -
-
-
-
-
-
-
- 查询结果 -
-
-
-
-
\ No newline at end of file +@model NavigatorBarModel +@{ + ViewBag.Title = "程序异常"; + Layout = "~/Views/Shared/_Admin.cshtml"; +} +@section css { + + + +} +@section Javascript { + + + + + + +} +@section header { + @Html.Partial("Header", Model) +} +@section navigator { + @Html.Partial("Navigator", Model) +} +
+
查询条件
+
+
+
+
+ +
+ + + + +
+
+
+ +
+ + + + +
+
+
+ + +
+ +
+
+
+
+
+ +
+
+
+ 查询结果 +
+
+
+
+
+@section modal { + + +}