升级到.net core 3.1;整体组件升级到最新版本

This commit is contained in:
2019-12-06 16:26:46 +08:00
parent 9fc5162230
commit e740282650
16 changed files with 179 additions and 61 deletions
@@ -10,6 +10,11 @@ using XCode;
using Newtonsoft.Json;
using COMCMS.Web.Common;
using Microsoft.AspNetCore.Http;
using System.IO;
using NewLife.Log;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.FileProviders;
using System.Text;
namespace COMCMS.Web.Areas.AdminCP.Controllers
{
@@ -17,6 +22,12 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
[DisplayName("后台权限")]
public class PermissionController : AdminBaseController
{
private IWebHostEnvironment _env;
public PermissionController(IWebHostEnvironment env)
{
_env = env;
}
#region 事件管理
/// <summary>
/// 目标事件
@@ -329,5 +340,77 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
return Json(tip);
}
#endregion
#region 系统运行日志
[HttpGet]
[MyAuthorize("viewlist", "runlogs")]
[DisplayName("系统运行日志")]
public IActionResult RunLogs()
{
string logPath = $"{_env.ContentRootPath}{Path.DirectorySeparatorChar}Log{Path.DirectorySeparatorChar}";
List<string> lognames = new List<string>();
try
{
if (Directory.Exists(logPath))
{
DirectoryInfo directory = new DirectoryInfo(logPath);
List<string> listFiles = new List<string>();
DirectoryInfo[] directorys = directory.GetDirectories();
FileInfo[] files;
files = directory.GetFiles();
foreach (FileInfo file in files)
{
lognames.Add(file.Name);
}
}
}
catch (Exception ex)
{
XTrace.WriteException(ex);
}
lognames.Reverse();//倒序排列一下
ViewBag.logPath = logPath;
return View(lognames);
}
#endregion
#region 获取日志详情
[HttpPost]
[MyAuthorize("viewlist", "runlogs")]
public async Task<IActionResult> GetRunLogDetail(string logname)
{
if (string.IsNullOrEmpty(logname))
{
return Content("错误日志名称!");
}
string logPath = $"{_env.ContentRootPath}{Path.DirectorySeparatorChar}Log{Path.DirectorySeparatorChar}";
string logFullPath = logPath + logname;
if (!System.IO.File.Exists(logFullPath))
{
return Content("系统找不到本日志文件!");
}
XTrace.WriteLine("查看日志:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
IFileProvider fileProvider = new PhysicalFileProvider(logPath);
StringBuilder detail = new StringBuilder();
using (Stream stream = fileProvider.GetFileInfo(logname).CreateReadStream())
{
byte[] buffer = new byte[stream.Length];
await stream.ReadAsync(buffer, 0, buffer.Length);
detail.Append(Encoding.Default.GetString(buffer));
}
//using (StreamReader fs = new StreamReader(logFullPath))
//{
// detail.Append(fs.ReadToEndAsync());
//}
//string detail = await System.IO.File.ReadAllTextAsync(logFullPath);
return Content(detail.ToString());
}
#endregion
}
}