增加了操作日志

This commit is contained in:
2025-12-26 18:59:27 +08:00
parent 108c97924f
commit 6ab500724f
3 changed files with 55 additions and 6 deletions

View File

@@ -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}");
}
}
}