refactor: 程序异常日志文件集合代码整理到 Helper 中
This commit is contained in:
parent
8d8e3977ac
commit
06dae58db1
|
@ -1,4 +1,5 @@
|
|||
using Bootstrap.Admin.Query;
|
||||
using Bootstrap.DataAccess;
|
||||
using Longbow.Web.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -6,7 +7,6 @@ using Microsoft.AspNetCore.Mvc.Filters;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Bootstrap.Admin.Controllers.Api
|
||||
|
@ -36,15 +36,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ButtonAuthorize(Url = "~/Admin/Exceptions", Auth = "log")]
|
||||
public IEnumerable<string> Post()
|
||||
{
|
||||
var filePath = Path.Combine(AppContext.BaseDirectory, "Error");
|
||||
return Directory.Exists(filePath)
|
||||
? Directory.GetFiles(filePath)
|
||||
.Where(f => Path.GetExtension(f).Equals(".log", StringComparison.OrdinalIgnoreCase))
|
||||
.Select(f => Path.GetFileNameWithoutExtension(f)).OrderByDescending(s => s)
|
||||
: Enumerable.Empty<string>();
|
||||
}
|
||||
public IEnumerable<string> Post() => ExceptionsHelper.RetrieveLogFiles();
|
||||
|
||||
/// <summary>
|
||||
/// 选中指定文件查看其内容方法
|
||||
|
|
|
@ -4,6 +4,8 @@ using PetaPoco;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bootstrap.DataAccess
|
||||
{
|
||||
|
@ -42,5 +44,18 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="endTime"></param>
|
||||
/// <returns></returns>
|
||||
public static Page<Exceptions> RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime) => DbContextManager.Create<Exceptions>()?.RetrievePages(po, startTime, endTime) ?? new Page<Exceptions>() { Items = new List<Exceptions>() };
|
||||
|
||||
/// <summary>
|
||||
/// 获得 Error 错误日志目录下所有文件
|
||||
/// </summary>
|
||||
public static IEnumerable<string> RetrieveLogFiles()
|
||||
{
|
||||
var filePath = Path.Combine(AppContext.BaseDirectory, "Error");
|
||||
return Directory.Exists(filePath)
|
||||
? Directory.GetFiles(filePath)
|
||||
.Where(f => Path.GetExtension(f).Equals(".log", StringComparison.OrdinalIgnoreCase))
|
||||
.Select(f => Path.GetFileNameWithoutExtension(f)).OrderByDescending(s => s)
|
||||
: Enumerable.Empty<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue