Fix log reading issue
This commit is contained in:
@@ -10,6 +10,7 @@ using AyaNova.Api.ControllerHelpers;
|
|||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace AyaNova.Api.Controllers
|
namespace AyaNova.Api.Controllers
|
||||||
{
|
{
|
||||||
@@ -77,9 +78,17 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
|
|
||||||
//Log
|
//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));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,6 +152,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
if (!System.IO.File.Exists(logFilePath))
|
if (!System.IO.File.Exists(logFilePath))
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
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}");
|
return PhysicalFile(logFilePath, "text/plain", $"{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")}-{logname}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user