diff --git a/ArchiSteamFarm/IPC/Controllers/Api/NLogController.cs b/ArchiSteamFarm/IPC/Controllers/Api/NLogController.cs index d13e1474c..776b493eb 100644 --- a/ArchiSteamFarm/IPC/Controllers/Api/NLogController.cs +++ b/ArchiSteamFarm/IPC/Controllers/Api/NLogController.cs @@ -70,10 +70,6 @@ public sealed class NLogController : ArchiController { return BadRequest(new GenericResponse(false, Strings.FormatErrorIsInvalid(nameof(lastAt)))); } - if (!Logging.LogFileExists) { - return BadRequest(new GenericResponse(false, Strings.FormatErrorIsEmpty(nameof(SharedInfo.LogFile)))); - } - string[]? lines = await Logging.ReadLogFileLines().ConfigureAwait(false); if ((lines == null) || (lines.Length == 0)) { diff --git a/ArchiSteamFarm/NLog/Logging.cs b/ArchiSteamFarm/NLog/Logging.cs index c04b5b8c1..19dd1463e 100644 --- a/ArchiSteamFarm/NLog/Logging.cs +++ b/ArchiSteamFarm/NLog/Logging.cs @@ -49,8 +49,6 @@ internal static class Logging { private const string GeneralLayout = $@"${{date:format=yyyy-MM-dd HH\:mm\:ss}}|${{processname}}-${{processid}}|${{level:uppercase=true}}|{LayoutMessage}"; private const string LayoutMessage = @"${logger}|${message}${onexception:inner= ${exception:format=toString,Data}}"; - internal static bool LogFileExists => File.Exists(SharedInfo.LogFile); - private static readonly ConcurrentHashSet ConsoleLoggingRules = []; private static readonly SemaphoreSlim ConsoleSemaphore = new(1, 1); @@ -304,8 +302,22 @@ internal static class Logging { } internal static async Task ReadLogFileLines() { + if (LogManager.Configuration == null) { + return File.Exists(SharedInfo.LogFile) ? await ReadLogFileLines(SharedInfo.LogFile).ConfigureAwait(false) : null; + } + + foreach (string fileName in LogManager.Configuration.LoggingRules.OrderBy(static rule => rule.Filters.Count).SelectMany(static rule => rule.Targets.Select(static target => target is WrapperTargetBase wrapper ? wrapper.WrappedTarget : target).OfType().Select(static fileTarget => fileTarget.FileName.Render(new LogEventInfo { TimeStamp = DateTime.UtcNow })).Where(File.Exists))) { + return await ReadLogFileLines(fileName).ConfigureAwait(false); + } + + return null; + } + + private static async Task ReadLogFileLines(string filePath) { + ArgumentException.ThrowIfNullOrEmpty(filePath); + try { - return await File.ReadAllLinesAsync(SharedInfo.LogFile).ConfigureAwait(false); + return await File.ReadAllLinesAsync(filePath).ConfigureAwait(false); } catch (Exception e) { ASF.ArchiLogger.LogGenericException(e);