增加了操作日志
This commit is contained in:
@@ -120,4 +120,31 @@ public class MonitorController : ControllerBase
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 获取系统操作日志(读取最新的 50 条)
|
||||
/// </summary>
|
||||
[HttpGet("system-logs")]
|
||||
public IActionResult GetSystemLogs()
|
||||
{
|
||||
try
|
||||
{
|
||||
var logPath = "user_actions.log";
|
||||
if (!System.IO.File.Exists(logPath))
|
||||
{
|
||||
return Ok(new List<string> { "暂无操作记录" });
|
||||
}
|
||||
|
||||
// 读取文件 -> 取最后50行 -> 倒序排列(最新在前)
|
||||
var logs = System.IO.File.ReadLines(logPath)
|
||||
.TakeLast(50)
|
||||
.Reverse()
|
||||
.ToList();
|
||||
return Ok(logs);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"读取日志失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user