diff --git a/ArchiSteamFarm/Logging.cs b/ArchiSteamFarm/Logging.cs index 40127cf9b..6273eabe0 100644 --- a/ArchiSteamFarm/Logging.cs +++ b/ArchiSteamFarm/Logging.cs @@ -35,11 +35,28 @@ namespace ArchiSteamFarm { private static readonly ConcurrentHashSet ConsoleLoggingRules = new ConcurrentHashSet(); + private static bool IsUsingCustomConfiguration; private static bool IsWaitingForUserInput; + internal static void EnableDebugLogging() { + if (IsUsingCustomConfiguration || (LogManager.Configuration == null)) { + return; + } + + bool reload = false; + foreach (LoggingRule rule in LogManager.Configuration.LoggingRules.Where(rule => rule.IsLoggingEnabledForLevel(LogLevel.Debug) && !rule.IsLoggingEnabledForLevel(LogLevel.Trace))) { + rule.EnableLoggingForLevel(LogLevel.Trace); + reload = true; + } + + if (reload) { + LogManager.ReconfigExistingLoggers(); + } + } + internal static void InitLoggers() { if (LogManager.Configuration != null) { - // User provided custom NLog config, or we have it set already, so don't override it + IsUsingCustomConfiguration = true; InitConsoleLoggers(); LogManager.ConfigurationChanged += OnConfigurationChanged; return; diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index 5d857254c..bb299efcd 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -35,6 +35,7 @@ using System.ServiceProcess; using System.Threading; using System.Threading.Tasks; using ArchiSteamFarm.Localization; +using NLog; using NLog.Targets; using SteamKit2; @@ -155,6 +156,8 @@ namespace ArchiSteamFarm { // If debugging is on, we prepare debug directory prior to running if (GlobalConfig.Debug) { + Logging.EnableDebugLogging(); + if (Directory.Exists(SharedInfo.DebugDirectory)) { try { Directory.Delete(SharedInfo.DebugDirectory, true); @@ -329,6 +332,7 @@ namespace ArchiSteamFarm { break; } + LogManager.Flush(); return true; } @@ -434,7 +438,6 @@ namespace ArchiSteamFarm { } ASF.ArchiLogger.LogFatalException((Exception) e.ExceptionObject); - await Task.Delay(1000).ConfigureAwait(false); // For writing stuff to logs await Exit(1).ConfigureAwait(false); } diff --git a/ArchiSteamFarm/SteamSaleEvent.cs b/ArchiSteamFarm/SteamSaleEvent.cs index 3f0a989a8..70121a5cb 100644 --- a/ArchiSteamFarm/SteamSaleEvent.cs +++ b/ArchiSteamFarm/SteamSaleEvent.cs @@ -56,9 +56,12 @@ namespace ArchiSteamFarm { return; } + Bot.ArchiLogger.LogGenericTrace(Strings.Starting); + for (byte i = 0; (i < MaxSingleQueuesDaily) && (await IsDiscoveryQueueAvailable().ConfigureAwait(false)).GetValueOrDefault(); i++) { HashSet queue = await Bot.ArchiWebHandler.GenerateNewDiscoveryQueue().ConfigureAwait(false); if ((queue == null) || (queue.Count == 0)) { + Bot.ArchiLogger.LogGenericTrace(string.Format(Strings.ErrorIsEmpty, nameof(queue))); break; } @@ -76,6 +79,8 @@ namespace ArchiSteamFarm { Bot.ArchiLogger.LogGenericInfo(string.Format(Strings.DoneClearingDiscoveryQueue, i)); } + + Bot.ArchiLogger.LogGenericTrace(Strings.Done); } private async Task IsDiscoveryQueueAvailable() { @@ -96,6 +101,8 @@ namespace ArchiSteamFarm { return null; } + Bot.ArchiLogger.LogGenericTrace(text); + // It'd make more sense to check against "Come back tomorrow", but it might not cover out-of-the-event queue bool result = text.StartsWith("You can get ", StringComparison.Ordinal); return result;