2016-11-15 18:44:54 +08:00
|
|
|
|
using Bootstrap.Admin.Models;
|
|
|
|
|
using Bootstrap.DataAccess;
|
2016-12-06 11:04:49 +08:00
|
|
|
|
using Longbow.Web.Mvc;
|
2016-11-15 18:44:54 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2016-11-17 21:36:02 +08:00
|
|
|
|
using System.Text;
|
2016-11-15 18:44:54 +08:00
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.Http;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class ExceptionsController : ApiController
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 显示所有异常
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public QueryData<Exceptions> Get([FromUri]QueryExceptionOption value)
|
|
|
|
|
{
|
|
|
|
|
return value.RetrieveData();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IEnumerable<string> Post()
|
|
|
|
|
{
|
|
|
|
|
var filePath = HttpContext.Current.Server.MapPath("~/App_Data/ErrorLog");
|
2016-11-15 19:51:03 +08:00
|
|
|
|
return Directory.GetFiles(filePath)
|
|
|
|
|
.Where(f => Path.GetExtension(f).Equals(".log", System.StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
.Select(f => Path.GetFileNameWithoutExtension(f)).OrderByDescending(s => s);
|
2016-11-15 18:44:54 +08:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPut]
|
2016-11-17 21:36:02 +08:00
|
|
|
|
public string Put([FromBody]string fileName)
|
2016-11-15 18:44:54 +08:00
|
|
|
|
{
|
|
|
|
|
var logName = HttpContext.Current.Server.MapPath(string.Format("~/App_Data/ErrorLog/{0}.log", fileName));
|
2016-11-17 21:36:02 +08:00
|
|
|
|
if (!File.Exists(logName)) return "无此日志文件";
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
2016-11-15 18:44:54 +08:00
|
|
|
|
using (StreamReader reader = new StreamReader(logName))
|
|
|
|
|
{
|
2016-11-17 21:36:02 +08:00
|
|
|
|
while (!reader.EndOfStream)
|
|
|
|
|
{
|
|
|
|
|
var line = reader.ReadLine().Replace("<", "<").Replace(">", ">");
|
|
|
|
|
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);
|
|
|
|
|
};
|
2016-11-15 18:44:54 +08:00
|
|
|
|
}
|
2016-11-17 21:36:02 +08:00
|
|
|
|
return sb.ToString();
|
2016-11-15 18:44:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|