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)
.Where(f => Path.GetExtension(f).Equals(".log", System.StringComparison.OrdinalIgnoreCase))
.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("<", "<").Replace(">", ">").Replace("\r\n", "") };
}
}
}
}