From eb656f26f3dceea48d8f3850f07b22f19963e45c Mon Sep 17 00:00:00 2001 From: JustArchi Date: Tue, 24 Jul 2018 20:37:14 +0200 Subject: [PATCH] Fix HistoryTarget when using custom NLog configuration --- ArchiSteamFarm/Logging.cs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/ArchiSteamFarm/Logging.cs b/ArchiSteamFarm/Logging.cs index 6c7be6504..e1d4cd5ec 100644 --- a/ArchiSteamFarm/Logging.cs +++ b/ArchiSteamFarm/Logging.cs @@ -80,20 +80,31 @@ namespace ArchiSteamFarm { } internal static void InitHistoryLogger() { - if (IsUsingCustomConfiguration || (LogManager.Configuration == null)) { + if (LogManager.Configuration == null) { return; } - // TODO: We could use some nice HTML layout for this - HistoryTarget historyTarget = new HistoryTarget("History") { - Layout = GeneralLayout, - MaxCount = 20 - }; + HistoryTarget historyTarget; - LogManager.Configuration.AddTarget(historyTarget); - LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, historyTarget)); + if (IsUsingCustomConfiguration) { + historyTarget = LogManager.Configuration.AllTargets.OfType().FirstOrDefault(); + + if (historyTarget == null) { + return; + } + } else { + // TODO: We could use some nice HTML layout for this + historyTarget = new HistoryTarget("History") { + Layout = GeneralLayout, + MaxCount = 20 + }; + + LogManager.Configuration.AddTarget(historyTarget); + LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, historyTarget)); + + LogManager.ReconfigExistingLoggers(); + } - LogManager.ReconfigExistingLoggers(); IPC.OnNewHistoryTarget(historyTarget); } @@ -163,4 +174,4 @@ namespace ArchiSteamFarm { } } } -} \ No newline at end of file +}