完善程序异常模块,增加查看服务器日志功能

This commit is contained in:
Argo-Lenovo 2016-11-15 18:44:54 +08:00
parent 1be3ff60d7
commit 605b0e4e3f
9 changed files with 235 additions and 149 deletions

View File

@ -0,0 +1 @@
请不要删除此目录

View File

@ -101,6 +101,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Content Include="App_Data\ErrorLog\Readme.txt" />
<Content Include="Content\css\admin-responsive.css" />
<Content Include="Content\css\admin.css" />
<Content Include="Content\css\blue.css" />
@ -294,7 +295,6 @@
<Content Include="Views\Home\Register.cshtml" />
<Content Include="Views\Admin\Notifications.cshtml" />
<Content Include="Views\Admin\Infos.cshtml" />
<Content Include="Views\Admin\Excep.cshtml" />
<Content Include="Views\Admin\Exceptions.cshtml" />
<Content Include="Views\Admin\Messages.cshtml" />
<None Include="Web.Debug.config">
@ -304,9 +304,7 @@
<DependentUpon>Web.config</DependentUpon>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<ProjectReference Include="..\Bootstrap.DataAccess\Bootstrap.DataAccess.csproj">
<Project>{af16ca71-b8c6-4f51-b38c-0c0300fdebd7}</Project>

View File

@ -96,7 +96,7 @@
right: 16px;
top: 62px;
bottom: 80px;
overflow-y: scroll;
overflow: auto;
}
.icon-content .modal-footer {

View File

@ -246,7 +246,7 @@
var htmlTemplate = '<div class="form-group checkbox col-lg-3 col-xs-4"><label class="tooltips" data-placement="top" data-original-title="{3}" title="{3}"><input type="checkbox" value="{0}" {2}/>{1}</label></div>';
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,6 +354,7 @@
Group.saveGroupsByRoleId = function (roleId, groupIds, callback) {
processData.call(this, { Id: roleId, callback: callback, method: "PUT", data: { type: "role", groupIds: groupIds } });
};
// Menus
Menu = {
url: '../api/Menus/',
@ -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('<div class="form-group col-lg-3 col-md-3 col-sm-4 col-xs-6"><a href="#">{0}</a></div>', 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);

View File

@ -113,18 +113,6 @@ namespace Bootstrap.Admin.Controllers
///
/// </summary>
/// <returns></returns>
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", "</br>"));
}
return View();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public ActionResult Exceptions()
{
var v = new NavigatorBarModel("~/Admin/Exceptions");

View File

@ -1,5 +1,9 @@
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
@ -16,5 +20,29 @@ namespace Bootstrap.Admin.Controllers
{
return value.RetrieveData();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
[HttpPost]
public IEnumerable<string> Post()
{
var filePath = HttpContext.Current.Server.MapPath("~/App_Data/ErrorLog");
return Directory.GetFiles(filePath).Select(f => Path.GetFileNameWithoutExtension(f)).OrderByDescending(s => s);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
[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", "</br>") };
}
}
}
}

View File

@ -1,35 +1,23 @@
$(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"
}
}),
})
var $dialog = $('#dialogNew');
var $dataForm = $('#dataForm');
var $dataFormDetail = $('#dataFormDetail');
var $errorList = $('#errorList');
var $errorDetail = $('#errorDetail');
var $errorDetailTitle = $('#myDetailModalLabel');
$('table').smartTable({
url: '../api/Exceptions', //请求后台的URL*
sortName: 'AppDomainName',
queryParams: function (params) { return $.extend(params, { OperateTimeStart: $("#txt_operate_start").val(), OperateTimeEnd: $("#txt_operate_end").val() }); }, //传递参数(*
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: "APP域名", field: "AppDomainName", sortable: true },
{ title: "错误页", field: "ErrorPage", sortable: false },
{ title: "请求网址", field: "ErrorPage", sortable: false },
{ title: "用户名", field: "UserID", sortable: false },
{ title: "IP", field: "UserIp", sortable: false },
{ title: "错误", field: "Message", 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", " ");
title: "异常捕获时间", field: "LogTime", sortable: true, formatter: function (value, row, index) {
return new Date(value).format("yyyy-MM-dd HH:mm:ss");
}
}
]
@ -39,4 +27,27 @@
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('<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);
});
});
$errorDetail.on('click', 'button', function () {
$errorDetail.hide();
$errorList.show();
});
});

View File

@ -1,5 +0,0 @@
@{
ViewBag.Title = "Excep";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div>@ViewBag.Content</div>

View File

@ -6,6 +6,7 @@
@section css {
<link href="~/Content/css/bootstrap-table.css" rel="stylesheet" />
<link href="~/Content/css/bootstrap-datetimepicker.css" rel="stylesheet" />
<link href="~/Content/css/fa.css" rel="stylesheet" />
}
@section Javascript {
<script src="~/content/js/bootstrap-table.js"></script>
@ -48,10 +49,21 @@
<label class="sr-only"></label>
<button type="button" id="btn_query" class="btn btn-primary form-control"><span class="glyphicon glyphicon-search" aria-hidden="true"></span>查询</button>
</div>
<div class="toolbar btn-group dropdown">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button"><i class="fa fa-gear"></i></button>
<div class="dropdown-menu">
<a id="tb_view" href="#" title="查看明细"><i class="fa fa-file-text-o"></i></a>
</div>
</div>
</div>
</form>
</div>
</div>
<div id="toolbar" class="btn-group">
<button id="btn_view" type="button" class="btn btn-danger">
<span class="fa fa-file-text-o" aria-hidden="true"></span>服务器日志
</button>
</div>
<div class="panel panel-default">
<div class="panel-heading">
查询结果
@ -60,3 +72,37 @@
<table></table>
</div>
</div>
@section modal {
<div class="modal fade" id="dialogNew" tabindex="-1" role="dialog" data-backdrop="static" aria-labelledby="myModalLabel" aria-hidden="true">
<div id="errorList" class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">程序异常日志窗口</h4>
</div>
<div class="modal-body">
<form class="form-inline" id="dataForm" name="dataForm" role="form"><div class="row"></div></form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
关闭
</button>
</div>
</div>
</div>
</div>
<div id="errorDetail" class="modal-content icon-content">
<div class="modal-header">
<button type="button" class="close" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myDetailModalLabel">程序异常日志窗口</h4>
</div>
<div class="modal-body">
<div id="dataFormDetail"><div class="text-center"><i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i></div></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default">
关闭
</button>
</div>
</div>
}