ly/Controllers/LogController.cs

47 lines
1.4 KiB
C#
Raw Permalink Normal View History

2025-03-28 15:20:31 +00:00
using LY.App.Service;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
2025-03-29 01:53:17 +00:00
using Microsoft.Extensions.Logging;
2025-03-28 15:20:31 +00:00
namespace LY.App.Controllers
{
/// <summary>
/// 日志控制器
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class LogController : ControllerBase
{
private readonly LogService _logService;
public LogController(LogService logService)
{
_logService = logService;
}
/// <summary>
/// 获取日志列表
/// </summary>
/// <param name="pageNum">页码</param>
/// <param name="pageSize">页大小</param>
/// <param name="key">页大小</param>
/// <returns></returns>
[HttpGet("list")]
public async Task<IActionResult> GetLogs(int pageNum = 1, int pageSize = 10, string key = null)
{
var result = await _logService.List(pageNum, pageSize, key);
return Ok(result);
}
2025-03-29 01:53:17 +00:00
/// <summary>
/// 导出日志
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
[HttpGet("export")]
public async Task<IActionResult> Export(string key = null)
{
var result = await _logService.DownLog(key);
return File(result, "text/plain", $"{DateTime.Now.ToString("yyyy-MM-dd")}__logfile.txt");
}
2025-03-28 15:20:31 +00:00
}
}