From f7b52751cf39d4cfebc7283aeb3a868a5a58f675 Mon Sep 17 00:00:00 2001 From: mx57 <38256814+mx57@users.noreply.github.com> Date: Mon, 7 Sep 2026 20:10:21 +0000 Subject: [PATCH] Add log file download feature on Web Dashboard Added DownloadLog endpoint in HomeController to safely stream active log files with FileShare.ReadWrite and integrated download buttons into the Live Log Monitor UI. --- .../Controllers/HomeController.cs | 23 +++++++++++++++++++ .../Static/Scripts/Views/dashboard.js | 1 + IntelliTrader.Web/Views/Home/Dashboard.cshtml | 19 ++++++++++++--- magda_agent_system/agent_tasks.json | 19 ++++++++++++++- 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/IntelliTrader.Web/Controllers/HomeController.cs b/IntelliTrader.Web/Controllers/HomeController.cs index 27edbbc..ed81afb 100644 --- a/IntelliTrader.Web/Controllers/HomeController.cs +++ b/IntelliTrader.Web/Controllers/HomeController.cs @@ -538,6 +538,29 @@ public IActionResult Help(string lang = "en") return View(model); } + [HttpGet] + public IActionResult DownloadLog(string type = "general") + { + try + { + string pattern = "general".Equals(type, StringComparison.OrdinalIgnoreCase) ? "*-general.txt" : "*-trades.txt"; + string filePath = GetLatestLogFilePath(pattern); + + if (string.IsNullOrEmpty(filePath) || !System.IO.File.Exists(filePath)) + { + return NotFound("No log file found."); + } + + string fileName = Path.GetFileName(filePath); + var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + return File(fileStream, "text/plain", fileName); + } + catch (Exception ex) + { + return BadRequest($"Error downloading log file: {ex.Message}"); + } + } + [HttpGet] public IActionResult PollLogs(string type = "general", int maxLines = 100) { diff --git a/IntelliTrader.Web/Static/Scripts/Views/dashboard.js b/IntelliTrader.Web/Static/Scripts/Views/dashboard.js index 1a2d24f..63acb65 100644 --- a/IntelliTrader.Web/Static/Scripts/Views/dashboard.js +++ b/IntelliTrader.Web/Static/Scripts/Views/dashboard.js @@ -205,6 +205,7 @@ function setLogType(type) { $("#logTypeGeneralBtn").removeClass("active"); } + $("#downloadLogTopBtn").attr("href", "/Home/DownloadLog?type=" + type); $("#logTerminal").html('