Fix log reading issue

This commit is contained in:
2022-01-13 20:34:49 +00:00
parent 7c3f1bc20d
commit 2e59a93fac

View File

@@ -10,6 +10,7 @@ using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
using System.Threading.Tasks;
using System;
using System.IO;
namespace AyaNova.Api.Controllers
{
@@ -77,9 +78,17 @@ namespace AyaNova.Api.Controllers
//Log
// EventLogProcessor.AddEntry(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.LogFile, AyaEvent.Retrieved,logname), ct);
return Content(System.IO.File.ReadAllText(logFilePath));
//nlog update now locks file for writing so needs to be opened this way
FileStreamOptions fso = new FileStreamOptions();
fso.Access = FileAccess.Read;
fso.Mode = FileMode.Open;
fso.Share = FileShare.ReadWrite;
using (StreamReader sr = new StreamReader(logFilePath, fso))
{
return Content(sr.ReadToEnd());
}
//return Content(System.IO.File.ReadAllText(logFilePath));
}
@@ -142,7 +151,8 @@ namespace AyaNova.Api.Controllers
var logFilePath = System.IO.Path.Combine(ServerBootConfig.AYANOVA_LOG_PATH, logname);
if (!System.IO.File.Exists(logFilePath))
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
//Note: this works with new Nlog file locking for write so it must be opening it as read and shareable
return PhysicalFile(logFilePath, "text/plain", $"{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")}-{logname}");
}