From 8b3b8229385328bdf31683635033b0c658b0311a Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sun, 6 Nov 2016 12:06:02 +0100 Subject: [PATCH] Rewrite entire ASF logging, as preparation for #354 --- ArchiSteamFarm/ASF.cs | 64 ++--- ArchiSteamFarm/ArchiHandler.cs | 42 ++-- ArchiSteamFarm/ArchiLogger.cs | 126 ++++++++++ ArchiSteamFarm/ArchiSteamFarm.csproj | 1 + ArchiSteamFarm/ArchiWebHandler.cs | 139 +++++------ ArchiSteamFarm/Bot.cs | 248 ++++++++++--------- ArchiSteamFarm/BotConfig.cs | 8 +- ArchiSteamFarm/BotDatabase.cs | 10 +- ArchiSteamFarm/CardsFarmer.cs | 106 ++++---- ArchiSteamFarm/CryptoHelper.cs | 22 +- ArchiSteamFarm/Debugging.cs | 4 +- ArchiSteamFarm/Events.cs | 28 ++- ArchiSteamFarm/GlobalConfig.cs | 16 +- ArchiSteamFarm/GlobalDatabase.cs | 10 +- ArchiSteamFarm/InMemoryServerListProvider.cs | 2 +- ArchiSteamFarm/JSON/Steam.cs | 38 +-- ArchiSteamFarm/Logging.cs | 91 +------ ArchiSteamFarm/MobileAuthenticator.cs | 42 ++-- ArchiSteamFarm/Program.cs | 38 +-- ArchiSteamFarm/Runtime.cs | 28 +-- ArchiSteamFarm/Trading.cs | 14 +- ArchiSteamFarm/Utilities.cs | 4 +- ArchiSteamFarm/WCF.cs | 41 ++- ArchiSteamFarm/WebBrowser.cs | 94 +++---- GUI/BotStatusForm.cs | 2 +- GUI/Events.cs | 35 ++- GUI/GUI.csproj | 3 + GUI/Logging.cs | 91 +------ GUI/MainForm.cs | 8 +- GUI/Program.cs | 18 +- 30 files changed, 701 insertions(+), 672 deletions(-) create mode 100644 ArchiSteamFarm/ArchiLogger.cs diff --git a/ArchiSteamFarm/ASF.cs b/ArchiSteamFarm/ASF.cs index d652dcc6d..8e83d91b0 100644 --- a/ArchiSteamFarm/ASF.cs +++ b/ArchiSteamFarm/ASF.cs @@ -42,6 +42,8 @@ namespace ArchiSteamFarm { } } + internal static readonly ArchiLogger ArchiLogger = new ArchiLogger(SharedInfo.ASF); + private static readonly ConcurrentDictionary LastWriteTimes = new ConcurrentDictionary(); private static Timer AutoUpdatesTimer; @@ -50,7 +52,7 @@ namespace ArchiSteamFarm { internal static async Task CheckForUpdate(bool updateOverride = false) { string exeFile = Assembly.GetEntryAssembly().Location; if (string.IsNullOrEmpty(exeFile)) { - Logging.LogNullError(nameof(exeFile)); + ArchiLogger.LogNullError(nameof(exeFile)); return; } @@ -64,8 +66,8 @@ namespace ArchiSteamFarm { try { File.Delete(oldExeFile); } catch (Exception e) { - Logging.LogGenericException(e); - Logging.LogGenericError("Could not remove old ASF binary, please remove " + oldExeFile + " manually in order for update function to work!"); + ArchiLogger.LogGenericException(e); + ArchiLogger.LogGenericError("Could not remove old ASF binary, please remove " + oldExeFile + " manually in order for update function to work!"); } } @@ -81,7 +83,7 @@ namespace ArchiSteamFarm { TimeSpan.FromDays(1) // Period ); - Logging.LogGenericInfo("ASF will automatically check for new versions every 24 hours"); + ArchiLogger.LogGenericInfo("ASF will automatically check for new versions every 24 hours"); } string releaseURL = SharedInfo.GithubReleaseURL; @@ -89,20 +91,20 @@ namespace ArchiSteamFarm { releaseURL += "/latest"; } - Logging.LogGenericInfo("Checking new version..."); + ArchiLogger.LogGenericInfo("Checking new version..."); GitHub.ReleaseResponse releaseResponse; if (Program.GlobalConfig.UpdateChannel == GlobalConfig.EUpdateChannel.Stable) { releaseResponse = await Program.WebBrowser.UrlGetToJsonResultRetry(releaseURL).ConfigureAwait(false); if (releaseResponse == null) { - Logging.LogGenericWarning("Could not check latest version!"); + ArchiLogger.LogGenericWarning("Could not check latest version!"); return; } } else { List releases = await Program.WebBrowser.UrlGetToJsonResultRetry>(releaseURL).ConfigureAwait(false); if ((releases == null) || (releases.Count == 0)) { - Logging.LogGenericWarning("Could not check latest version!"); + ArchiLogger.LogGenericWarning("Could not check latest version!"); return; } @@ -110,33 +112,33 @@ namespace ArchiSteamFarm { } if (string.IsNullOrEmpty(releaseResponse.Tag)) { - Logging.LogGenericWarning("Could not check latest version!"); + ArchiLogger.LogGenericWarning("Could not check latest version!"); return; } Version newVersion = new Version(releaseResponse.Tag); - Logging.LogGenericInfo("Local version: " + SharedInfo.Version + " | Remote version: " + newVersion); + ArchiLogger.LogGenericInfo("Local version: " + SharedInfo.Version + " | Remote version: " + newVersion); if (SharedInfo.Version.CompareTo(newVersion) >= 0) { // If local version is the same or newer than remote version return; } if (!updateOverride && !Program.GlobalConfig.AutoUpdates) { - Logging.LogGenericInfo("New version is available!"); - Logging.LogGenericInfo("Consider updating yourself!"); + ArchiLogger.LogGenericInfo("New version is available!"); + ArchiLogger.LogGenericInfo("Consider updating yourself!"); await Task.Delay(5000).ConfigureAwait(false); return; } if (File.Exists(oldExeFile)) { - Logging.LogGenericWarning("Refusing to proceed with auto update as old " + oldExeFile + " binary could not be removed, please remove it manually"); + ArchiLogger.LogGenericWarning("Refusing to proceed with auto update as old " + oldExeFile + " binary could not be removed, please remove it manually"); return; } // Auto update logic starts here if (releaseResponse.Assets == null) { - Logging.LogGenericWarning("Could not proceed with update because that version doesn't include assets!"); + ArchiLogger.LogGenericWarning("Could not proceed with update because that version doesn't include assets!"); return; } @@ -144,17 +146,17 @@ namespace ArchiSteamFarm { GitHub.ReleaseResponse.Asset binaryAsset = releaseResponse.Assets.FirstOrDefault(asset => !string.IsNullOrEmpty(asset.Name) && asset.Name.Equals(exeFileName, StringComparison.OrdinalIgnoreCase)); if (binaryAsset == null) { - Logging.LogGenericWarning("Could not proceed with update because there is no asset that relates to currently running binary!"); + ArchiLogger.LogGenericWarning("Could not proceed with update because there is no asset that relates to currently running binary!"); return; } if (string.IsNullOrEmpty(binaryAsset.DownloadURL)) { - Logging.LogGenericWarning("Could not proceed with update because download URL is empty!"); + ArchiLogger.LogGenericWarning("Could not proceed with update because download URL is empty!"); return; } - Logging.LogGenericInfo("Downloading new version..."); - Logging.LogGenericInfo("While waiting, consider donating if you appreciate the work being done :)"); + ArchiLogger.LogGenericInfo("Downloading new version..."); + ArchiLogger.LogGenericInfo("While waiting, consider donating if you appreciate the work being done :)"); byte[] result = await Program.WebBrowser.UrlGetToBytesRetry(binaryAsset.DownloadURL).ConfigureAwait(false); if (result == null) { @@ -167,7 +169,7 @@ namespace ArchiSteamFarm { try { File.WriteAllBytes(newExeFile, result); } catch (Exception e) { - Logging.LogGenericException(e); + ArchiLogger.LogGenericException(e); return; } @@ -175,7 +177,7 @@ namespace ArchiSteamFarm { try { File.Move(exeFile, oldExeFile); } catch (Exception e) { - Logging.LogGenericException(e); + ArchiLogger.LogGenericException(e); try { // Cleanup File.Delete(newExeFile); @@ -189,7 +191,7 @@ namespace ArchiSteamFarm { try { File.Move(newExeFile, exeFile); } catch (Exception e) { - Logging.LogGenericException(e); + ArchiLogger.LogGenericException(e); try { // Cleanup File.Move(oldExeFile, exeFile); @@ -200,14 +202,14 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericInfo("Update process finished!"); + ArchiLogger.LogGenericInfo("Update process finished!"); if (Program.GlobalConfig.AutoRestart) { - Logging.LogGenericInfo("Restarting..."); + ArchiLogger.LogGenericInfo("Restarting..."); await Task.Delay(5000).ConfigureAwait(false); Program.Restart(); } else { - Logging.LogGenericInfo("Exiting..."); + ArchiLogger.LogGenericInfo("Exiting..."); await Task.Delay(5000).ConfigureAwait(false); Program.Exit(); } @@ -232,7 +234,7 @@ namespace ArchiSteamFarm { private static async Task CreateBot(string botName) { if (string.IsNullOrEmpty(botName)) { - Logging.LogNullError(nameof(botName)); + ArchiLogger.LogNullError(nameof(botName)); return; } @@ -252,7 +254,7 @@ namespace ArchiSteamFarm { private static async void OnChanged(object sender, FileSystemEventArgs e) { if ((sender == null) || (e == null)) { - Logging.LogNullError(nameof(sender) + " || " + nameof(e)); + ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e)); return; } @@ -262,7 +264,7 @@ namespace ArchiSteamFarm { } if (botName.Equals(SharedInfo.ASF)) { - Logging.LogGenericError("Global config file has been changed, restarting..."); + ArchiLogger.LogGenericError("Global config file has been changed, restarting..."); Program.Restart(); return; } @@ -304,7 +306,7 @@ namespace ArchiSteamFarm { private static void OnCreated(object sender, FileSystemEventArgs e) { if ((sender == null) || (e == null)) { - Logging.LogNullError(nameof(sender) + " || " + nameof(e)); + ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e)); return; } @@ -318,7 +320,7 @@ namespace ArchiSteamFarm { private static void OnDeleted(object sender, FileSystemEventArgs e) { if ((sender == null) || (e == null)) { - Logging.LogNullError(nameof(sender) + " || " + nameof(e)); + ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e)); return; } @@ -328,7 +330,7 @@ namespace ArchiSteamFarm { } if (botName.Equals(SharedInfo.ASF)) { - Logging.LogGenericError("Global config file has been removed, exiting..."); + ArchiLogger.LogGenericError("Global config file has been removed, exiting..."); Program.Exit(1); return; } @@ -341,7 +343,7 @@ namespace ArchiSteamFarm { private static void OnRenamed(object sender, RenamedEventArgs e) { if ((sender == null) || (e == null)) { - Logging.LogNullError(nameof(sender) + " || " + nameof(e)); + ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e)); return; } @@ -351,7 +353,7 @@ namespace ArchiSteamFarm { } if (oldBotName.Equals(SharedInfo.ASF)) { - Logging.LogGenericError("Global config file has been renamed, exiting..."); + ArchiLogger.LogGenericError("Global config file has been renamed, exiting..."); Program.Exit(1); return; } diff --git a/ArchiSteamFarm/ArchiHandler.cs b/ArchiSteamFarm/ArchiHandler.cs index d04690488..c2da0e33e 100644 --- a/ArchiSteamFarm/ArchiHandler.cs +++ b/ArchiSteamFarm/ArchiHandler.cs @@ -34,14 +34,14 @@ using System.Threading.Tasks; namespace ArchiSteamFarm { internal sealed class ArchiHandler : ClientMsgHandler { - private readonly Bot Bot; + private readonly ArchiLogger ArchiLogger; - internal ArchiHandler(Bot bot) { - if (bot == null) { - throw new ArgumentNullException(nameof(bot)); + internal ArchiHandler(ArchiLogger archiLogger) { + if (archiLogger == null) { + throw new ArgumentNullException(nameof(archiLogger)); } - Bot = bot; + ArchiLogger = archiLogger; } /* @@ -151,7 +151,7 @@ namespace ArchiSteamFarm { KeyValue receiptInfo = new KeyValue(); using (MemoryStream ms = new MemoryStream(msg.purchase_receipt_info)) { if (!receiptInfo.TryReadAsBinary(ms)) { - Logging.LogNullError(nameof(ms)); + ASF.ArchiLogger.LogNullError(nameof(ms)); return; } } @@ -168,14 +168,14 @@ namespace ArchiSteamFarm { // Valid, coupons have PackageID of -1 (don't ask me why) packageID = lineItem["ItemAppID"].AsUnsignedInteger(); if (packageID == 0) { - Logging.LogNullError(nameof(packageID)); + ASF.ArchiLogger.LogNullError(nameof(packageID)); return; } } string gameName = lineItem["ItemDescription"].Value; if (string.IsNullOrEmpty(gameName)) { - Logging.LogNullError(nameof(gameName)); + ASF.ArchiLogger.LogNullError(nameof(gameName)); return; } @@ -290,7 +290,7 @@ namespace ArchiSteamFarm { internal void PlayGames(IEnumerable gameIDs, string gameName = null) { if (gameIDs == null) { - Logging.LogNullError(nameof(gameIDs), Bot.BotName); + ArchiLogger.LogNullError(nameof(gameIDs)); return; } @@ -321,7 +321,7 @@ namespace ArchiSteamFarm { internal async Task RedeemGuestPass(ulong guestPassID) { if (guestPassID == 0) { - Logging.LogNullError(nameof(guestPassID), Bot.BotName); + ArchiLogger.LogNullError(nameof(guestPassID)); return null; } @@ -340,14 +340,14 @@ namespace ArchiSteamFarm { try { return await new AsyncJob(Client, request.SourceJobID); } catch (Exception e) { - Logging.LogGenericException(e, Bot.BotName); + ArchiLogger.LogGenericException(e); return null; } } internal async Task RedeemKey(string key) { if (string.IsNullOrEmpty(key)) { - Logging.LogNullError(nameof(key), Bot.BotName); + ArchiLogger.LogNullError(nameof(key)); return null; } @@ -366,7 +366,7 @@ namespace ArchiSteamFarm { try { return await new AsyncJob(Client, request.SourceJobID); } catch (Exception e) { - Logging.LogGenericException(e, Bot.BotName); + ArchiLogger.LogGenericException(e); return null; } } @@ -382,7 +382,7 @@ namespace ArchiSteamFarm { public override void HandleMsg(IPacketMsg packetMsg) { if (packetMsg == null) { - Logging.LogNullError(nameof(packetMsg), Bot.BotName); + ArchiLogger.LogNullError(nameof(packetMsg)); return; } @@ -413,7 +413,7 @@ namespace ArchiSteamFarm { private void HandleFSOfflineMessageNotification(IPacketMsg packetMsg) { if (packetMsg == null) { - Logging.LogNullError(nameof(packetMsg), Bot.BotName); + ArchiLogger.LogNullError(nameof(packetMsg)); return; } @@ -423,7 +423,7 @@ namespace ArchiSteamFarm { private void HandleItemAnnouncements(IPacketMsg packetMsg) { if (packetMsg == null) { - Logging.LogNullError(nameof(packetMsg), Bot.BotName); + ArchiLogger.LogNullError(nameof(packetMsg)); return; } @@ -433,7 +433,7 @@ namespace ArchiSteamFarm { private void HandlePlayingSessionState(IPacketMsg packetMsg) { if (packetMsg == null) { - Logging.LogNullError(nameof(packetMsg), Bot.BotName); + ArchiLogger.LogNullError(nameof(packetMsg)); return; } @@ -443,7 +443,7 @@ namespace ArchiSteamFarm { private void HandlePurchaseResponse(IPacketMsg packetMsg) { if (packetMsg == null) { - Logging.LogNullError(nameof(packetMsg), Bot.BotName); + ArchiLogger.LogNullError(nameof(packetMsg)); return; } @@ -453,7 +453,7 @@ namespace ArchiSteamFarm { private void HandleRedeemGuestPassResponse(IPacketMsg packetMsg) { if (packetMsg == null) { - Logging.LogNullError(nameof(packetMsg), Bot.BotName); + ArchiLogger.LogNullError(nameof(packetMsg)); return; } @@ -463,7 +463,7 @@ namespace ArchiSteamFarm { private void HandleSharedLibraryLockStatus(IPacketMsg packetMsg) { if (packetMsg == null) { - Logging.LogNullError(nameof(packetMsg), Bot.BotName); + ArchiLogger.LogNullError(nameof(packetMsg)); return; } @@ -473,7 +473,7 @@ namespace ArchiSteamFarm { private void HandleUserNotifications(IPacketMsg packetMsg) { if (packetMsg == null) { - Logging.LogNullError(nameof(packetMsg), Bot.BotName); + ArchiLogger.LogNullError(nameof(packetMsg)); return; } diff --git a/ArchiSteamFarm/ArchiLogger.cs b/ArchiSteamFarm/ArchiLogger.cs new file mode 100644 index 000000000..1154d1644 --- /dev/null +++ b/ArchiSteamFarm/ArchiLogger.cs @@ -0,0 +1,126 @@ +/* + _ _ _ ____ _ _____ + / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ + / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ + / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| + + Copyright 2015-2016 Łukasz "JustArchi" Domeradzki + Contact: JustArchi@JustArchi.net + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Runtime.CompilerServices; +using NLog; + +namespace ArchiSteamFarm { + internal sealed class ArchiLogger { + private readonly Logger Logger; + + internal ArchiLogger(string name) { + if (string.IsNullOrEmpty(name)) { + throw new ArgumentNullException(nameof(name)); + } + + Logger = LogManager.GetLogger(name); + } + + internal void LogGenericError(string message, [CallerMemberName] string previousMethodName = null) { + if (string.IsNullOrEmpty(message)) { + LogNullError(nameof(message)); + return; + } + + Logger.Error($"{previousMethodName}() {message}"); + } + + internal void LogGenericException(Exception exception, [CallerMemberName] string previousMethodName = null) { + if (exception == null) { + LogNullError(nameof(exception)); + return; + } + + Logger.Error(exception, $"{previousMethodName}()"); + } + + [SuppressMessage("ReSharper", "LocalizableElement")] + internal void LogFatalException(Exception exception, [CallerMemberName] string previousMethodName = null) { + if (exception == null) { + LogNullError(nameof(exception)); + return; + } + + Logger.Fatal(exception, $"{previousMethodName}()"); + + // If LogManager has been initialized already, don't do anything else + if (LogManager.Configuration != null) { + return; + } + + // Otherwise, if we run into fatal exception before logging module is even initialized, write exception to classic log file + File.WriteAllText(SharedInfo.LogFile, DateTime.Now + " ASF V" + SharedInfo.Version + " has run into fatal exception before core logging module was even able to initialize!" + Environment.NewLine); + + while (true) { + File.AppendAllText(SharedInfo.LogFile, "[!] EXCEPTION: " + previousMethodName + "() " + exception.Message + Environment.NewLine + "StackTrace:" + Environment.NewLine + exception.StackTrace); + if (exception.InnerException != null) { + exception = exception.InnerException; + continue; + } + + break; + } + } + + internal void LogGenericWarning(string message, [CallerMemberName] string previousMethodName = null) { + if (string.IsNullOrEmpty(message)) { + LogNullError(nameof(message)); + return; + } + + Logger.Warn($"{previousMethodName}() {message}"); + } + + internal void LogGenericInfo(string message, [CallerMemberName] string previousMethodName = null) { + if (string.IsNullOrEmpty(message)) { + LogNullError(nameof(message)); + return; + } + + Logger.Info($"{previousMethodName}() {message}"); + } + + [SuppressMessage("ReSharper", "ExplicitCallerInfoArgument")] + internal void LogNullError(string nullObjectName, [CallerMemberName] string previousMethodName = null) { + if (string.IsNullOrEmpty(nullObjectName)) { + return; + } + + LogGenericError(nullObjectName + " is null!", previousMethodName); + } + + [SuppressMessage("ReSharper", "UnusedMember.Global")] + internal void LogGenericDebug(string message, [CallerMemberName] string previousMethodName = null) { + if (string.IsNullOrEmpty(message)) { + LogNullError(nameof(message)); + return; + } + + Logger.Debug($"{previousMethodName}() {message}"); + } + } +} diff --git a/ArchiSteamFarm/ArchiSteamFarm.csproj b/ArchiSteamFarm/ArchiSteamFarm.csproj index cbf7623a9..75764cabe 100644 --- a/ArchiSteamFarm/ArchiSteamFarm.csproj +++ b/ArchiSteamFarm/ArchiSteamFarm.csproj @@ -108,6 +108,7 @@ + Component diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index aaacafdc3..79cf80a98 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -21,6 +21,7 @@ limitations under the License. */ + using Newtonsoft.Json; using Newtonsoft.Json.Linq; using HtmlAgilityPack; @@ -62,7 +63,7 @@ namespace ArchiSteamFarm { private static uint GetAppIDFromMarketHashName(string hashName) { if (string.IsNullOrEmpty(hashName)) { - Logging.LogNullError(nameof(hashName)); + ASF.ArchiLogger.LogNullError(nameof(hashName)); return 0; } @@ -77,7 +78,7 @@ namespace ArchiSteamFarm { private static Steam.Item.EType GetItemType(string name) { if (string.IsNullOrEmpty(name)) { - Logging.LogNullError(nameof(name)); + ASF.ArchiLogger.LogNullError(nameof(name)); return Steam.Item.EType.Unknown; } @@ -109,32 +110,32 @@ namespace ArchiSteamFarm { private static bool ParseItems(Dictionary> descriptions, List input, HashSet output) { if ((descriptions == null) || (input == null) || (input.Count == 0) || (output == null)) { - Logging.LogNullError(nameof(descriptions) + " || " + nameof(input) + " || " + nameof(output)); + ASF.ArchiLogger.LogNullError(nameof(descriptions) + " || " + nameof(input) + " || " + nameof(output)); return false; } foreach (KeyValue item in input) { uint appID = item["appid"].AsUnsignedInteger(); if (appID == 0) { - Logging.LogNullError(nameof(appID)); + ASF.ArchiLogger.LogNullError(nameof(appID)); return false; } ulong contextID = item["contextid"].AsUnsignedLong(); if (contextID == 0) { - Logging.LogNullError(nameof(contextID)); + ASF.ArchiLogger.LogNullError(nameof(contextID)); return false; } ulong classID = item["classid"].AsUnsignedLong(); if (classID == 0) { - Logging.LogNullError(nameof(classID)); + ASF.ArchiLogger.LogNullError(nameof(classID)); return false; } uint amount = item["amount"].AsUnsignedInteger(); if (amount == 0) { - Logging.LogNullError(nameof(amount)); + ASF.ArchiLogger.LogNullError(nameof(amount)); return false; } @@ -161,7 +162,7 @@ namespace ArchiSteamFarm { Bot = bot; - WebBrowser = new WebBrowser(bot.BotName); + WebBrowser = new WebBrowser(bot.ArchiLogger); } public void Dispose() => SessionSemaphore.Dispose(); @@ -170,7 +171,7 @@ namespace ArchiSteamFarm { internal async Task Init(ulong steamID, EUniverse universe, string webAPIUserNonce, string parentalPin) { if ((steamID == 0) || (universe == EUniverse.Invalid) || string.IsNullOrEmpty(webAPIUserNonce) || string.IsNullOrEmpty(parentalPin)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(universe) + " || " + nameof(webAPIUserNonce) + " || " + nameof(parentalPin), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(universe) + " || " + nameof(webAPIUserNonce) + " || " + nameof(parentalPin)); return false; } @@ -195,7 +196,7 @@ namespace ArchiSteamFarm { byte[] cryptedLoginKey = SteamKit2.CryptoHelper.SymmetricEncrypt(loginKey, sessionKey); // Do the magic - Logging.LogGenericInfo("Logging in to ISteamUserAuth...", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Logging in to ISteamUserAuth..."); KeyValue authResult; using (dynamic iSteamUserAuth = WebAPI.GetInterface("ISteamUserAuth")) { @@ -210,25 +211,25 @@ namespace ArchiSteamFarm { secure: !Program.GlobalConfig.ForceHttp ); } catch (Exception e) { - Logging.LogGenericException(e, Bot.BotName); + Bot.ArchiLogger.LogGenericException(e); return false; } } if (authResult == null) { - Logging.LogNullError(nameof(authResult), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(authResult)); return false; } string steamLogin = authResult["token"].Value; if (string.IsNullOrEmpty(steamLogin)) { - Logging.LogNullError(nameof(steamLogin), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(steamLogin)); return false; } string steamLoginSecure = authResult["tokensecure"].Value; if (string.IsNullOrEmpty(steamLoginSecure)) { - Logging.LogNullError(nameof(steamLoginSecure), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(steamLoginSecure)); return false; } @@ -241,7 +242,7 @@ namespace ArchiSteamFarm { WebBrowser.CookieContainer.Add(new Cookie("steamLoginSecure", steamLoginSecure, "/", "." + SteamCommunityHost)); WebBrowser.CookieContainer.Add(new Cookie("steamLoginSecure", steamLoginSecure, "/", "." + SteamStoreHost)); - Logging.LogGenericInfo("Success!", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Success!"); // Unlock Steam Parental if needed if (!parentalPin.Equals("0")) { @@ -272,13 +273,13 @@ namespace ArchiSteamFarm { foreach (string miniProfile in htmlNodes.Select(htmlNode => htmlNode.GetAttributeValue("data-miniprofile", null))) { if (string.IsNullOrEmpty(miniProfile)) { - Logging.LogNullError(nameof(miniProfile), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(miniProfile)); return null; } uint steamID3; if (!uint.TryParse(miniProfile, out steamID3) || (steamID3 == 0)) { - Logging.LogNullError(nameof(steamID3), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(steamID3)); return null; } @@ -291,7 +292,7 @@ namespace ArchiSteamFarm { internal async Task JoinGroup(ulong groupID) { if (groupID == 0) { - Logging.LogNullError(nameof(groupID), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(groupID)); return false; } @@ -301,7 +302,7 @@ namespace ArchiSteamFarm { string sessionID = WebBrowser.CookieContainer.GetCookieValue(SteamCommunityURL, "sessionid"); if (string.IsNullOrEmpty(sessionID)) { - Logging.LogNullError(nameof(sessionID), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(sessionID)); return false; } @@ -316,7 +317,7 @@ namespace ArchiSteamFarm { internal async Task GetConfirmations(string deviceID, string confirmationHash, uint time) { if (string.IsNullOrEmpty(deviceID) || string.IsNullOrEmpty(confirmationHash) || (time == 0)) { - Logging.LogNullError(nameof(deviceID) + " || " + nameof(confirmationHash) + " || " + nameof(time), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(deviceID) + " || " + nameof(confirmationHash) + " || " + nameof(time)); return null; } @@ -330,7 +331,7 @@ namespace ArchiSteamFarm { internal async Task GetConfirmationDetails(string deviceID, string confirmationHash, uint time, MobileAuthenticator.Confirmation confirmation) { if (string.IsNullOrEmpty(deviceID) || string.IsNullOrEmpty(confirmationHash) || (time == 0) || (confirmation == null)) { - Logging.LogNullError(nameof(deviceID) + " || " + nameof(confirmationHash) + " || " + nameof(time) + " || " + nameof(confirmation), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(deviceID) + " || " + nameof(confirmationHash) + " || " + nameof(time) + " || " + nameof(confirmation)); return null; } @@ -351,7 +352,7 @@ namespace ArchiSteamFarm { internal async Task HandleConfirmation(string deviceID, string confirmationHash, uint time, uint confirmationID, ulong confirmationKey, bool accept) { if (string.IsNullOrEmpty(deviceID) || string.IsNullOrEmpty(confirmationHash) || (time == 0) || (confirmationID == 0) || (confirmationKey == 0)) { - Logging.LogNullError(nameof(deviceID) + " || " + nameof(confirmationHash) + " || " + nameof(time) + " || " + nameof(confirmationID) + " || " + nameof(confirmationKey), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(deviceID) + " || " + nameof(confirmationHash) + " || " + nameof(time) + " || " + nameof(confirmationID) + " || " + nameof(confirmationKey)); return null; } @@ -367,7 +368,7 @@ namespace ArchiSteamFarm { internal async Task HandleConfirmations(string deviceID, string confirmationHash, uint time, HashSet confirmations, bool accept) { if (string.IsNullOrEmpty(deviceID) || string.IsNullOrEmpty(confirmationHash) || (time == 0) || (confirmations == null) || (confirmations.Count == 0)) { - Logging.LogNullError(nameof(deviceID) + " || " + nameof(confirmationHash) + " || " + nameof(time) + " || " + nameof(confirmations), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(deviceID) + " || " + nameof(confirmationHash) + " || " + nameof(time) + " || " + nameof(confirmations)); return null; } @@ -414,19 +415,19 @@ namespace ArchiSteamFarm { foreach (XmlNode xmlNode in xmlNodeList) { XmlNode appNode = xmlNode.SelectSingleNode("appID"); if (appNode == null) { - Logging.LogNullError(nameof(appNode), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(appNode)); return null; } uint appID; if (!uint.TryParse(appNode.InnerText, out appID)) { - Logging.LogNullError(nameof(appID), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(appID)); return null; } XmlNode nameNode = xmlNode.SelectSingleNode("name"); if (nameNode == null) { - Logging.LogNullError(nameof(nameNode), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(nameNode)); return null; } @@ -438,7 +439,7 @@ namespace ArchiSteamFarm { internal Dictionary GetOwnedGames(ulong steamID) { if ((steamID == 0) || string.IsNullOrEmpty(Bot.BotConfig.SteamApiKey)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(Bot.BotConfig.SteamApiKey), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(Bot.BotConfig.SteamApiKey)); return null; } @@ -454,13 +455,13 @@ namespace ArchiSteamFarm { secure: !Program.GlobalConfig.ForceHttp ); } catch (Exception e) { - Logging.LogGenericException(e, Bot.BotName); + Bot.ArchiLogger.LogGenericException(e); } } } if (response == null) { - Logging.LogGenericWarning("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); + Bot.ArchiLogger.LogGenericWarning("Request failed even after " + WebBrowser.MaxRetries + " tries"); return null; } @@ -468,7 +469,7 @@ namespace ArchiSteamFarm { foreach (KeyValue game in response["games"].Children) { uint appID = game["appid"].AsUnsignedInteger(); if (appID == 0) { - Logging.LogNullError(nameof(appID), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(appID)); return null; } @@ -490,7 +491,7 @@ namespace ArchiSteamFarm { secure: !Program.GlobalConfig.ForceHttp ); } catch (Exception e) { - Logging.LogGenericException(e, Bot.BotName); + Bot.ArchiLogger.LogGenericException(e); } } } @@ -499,13 +500,13 @@ namespace ArchiSteamFarm { return response["server_time"].AsUnsignedInteger(); } - Logging.LogGenericWarning("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); + Bot.ArchiLogger.LogGenericWarning("Request failed even after " + WebBrowser.MaxRetries + " tries"); return 0; } internal async Task GetTradeHoldDuration(ulong tradeID) { if (tradeID == 0) { - Logging.LogNullError(nameof(tradeID), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(tradeID)); return null; } @@ -524,13 +525,13 @@ namespace ArchiSteamFarm { string text = htmlNode.InnerText; if (string.IsNullOrEmpty(text)) { - Logging.LogNullError(nameof(text), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(text)); return null; } int index = text.IndexOf("g_daysTheirEscrow = ", StringComparison.Ordinal); if (index < 0) { - Logging.LogNullError(nameof(index), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(index)); return null; } @@ -539,7 +540,7 @@ namespace ArchiSteamFarm { index = text.IndexOf(';'); if (index < 0) { - Logging.LogNullError(nameof(index), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(index)); return null; } @@ -550,13 +551,13 @@ namespace ArchiSteamFarm { return holdDuration; } - Logging.LogNullError(nameof(holdDuration), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(holdDuration)); return null; } internal async Task RedeemWalletKey(string key) { if (string.IsNullOrEmpty(key)) { - Logging.LogNullError(nameof(key), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(key)); return ArchiHandler.PurchaseResponseCallback.EPurchaseResult.Unknown; } @@ -575,7 +576,7 @@ namespace ArchiSteamFarm { internal HashSet GetActiveTradeOffers() { if (string.IsNullOrEmpty(Bot.BotConfig.SteamApiKey)) { - Logging.LogNullError(nameof(Bot.BotConfig.SteamApiKey), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(Bot.BotConfig.SteamApiKey)); return null; } @@ -592,13 +593,13 @@ namespace ArchiSteamFarm { secure: !Program.GlobalConfig.ForceHttp ); } catch (Exception e) { - Logging.LogGenericException(e, Bot.BotName); + Bot.ArchiLogger.LogGenericException(e); } } } if (response == null) { - Logging.LogGenericWarning("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); + Bot.ArchiLogger.LogGenericWarning("Request failed even after " + WebBrowser.MaxRetries + " tries"); return null; } @@ -606,7 +607,7 @@ namespace ArchiSteamFarm { foreach (KeyValue description in response["descriptions"].Children) { ulong classID = description["classid"].AsUnsignedLong(); if (classID == 0) { - Logging.LogNullError(nameof(classID), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(classID)); return null; } @@ -639,7 +640,7 @@ namespace ArchiSteamFarm { foreach (KeyValue trade in response["trade_offers_received"].Children) { Steam.TradeOffer.ETradeOfferState state = trade["trade_offer_state"].AsEnum(); if (state == Steam.TradeOffer.ETradeOfferState.Unknown) { - Logging.LogNullError(nameof(state)); + Bot.ArchiLogger.LogNullError(nameof(state)); return null; } @@ -649,13 +650,13 @@ namespace ArchiSteamFarm { ulong tradeOfferID = trade["tradeofferid"].AsUnsignedLong(); if (tradeOfferID == 0) { - Logging.LogNullError(nameof(tradeOfferID)); + Bot.ArchiLogger.LogNullError(nameof(tradeOfferID)); return null; } uint otherSteamID3 = trade["accountid_other"].AsUnsignedInteger(); if (otherSteamID3 == 0) { - Logging.LogNullError(nameof(otherSteamID3)); + Bot.ArchiLogger.LogNullError(nameof(otherSteamID3)); return null; } @@ -664,7 +665,7 @@ namespace ArchiSteamFarm { List itemsToGive = trade["items_to_give"].Children; if (itemsToGive.Count > 0) { if (!ParseItems(descriptions, itemsToGive, tradeOffer.ItemsToGive)) { - Logging.LogGenericError("Parsing " + nameof(itemsToGive) + " failed!", Bot.BotName); + Bot.ArchiLogger.LogGenericError("Parsing " + nameof(itemsToGive) + " failed!"); return null; } } @@ -672,7 +673,7 @@ namespace ArchiSteamFarm { List itemsToReceive = trade["items_to_receive"].Children; if (itemsToReceive.Count > 0) { if (!ParseItems(descriptions, itemsToReceive, tradeOffer.ItemsToReceive)) { - Logging.LogGenericError("Parsing " + nameof(itemsToReceive) + " failed!", Bot.BotName); + Bot.ArchiLogger.LogGenericError("Parsing " + nameof(itemsToReceive) + " failed!"); return null; } } @@ -685,7 +686,7 @@ namespace ArchiSteamFarm { internal async Task AcceptTradeOffer(ulong tradeID) { if (tradeID == 0) { - Logging.LogNullError(nameof(tradeID), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(tradeID)); return; } @@ -695,7 +696,7 @@ namespace ArchiSteamFarm { string sessionID = WebBrowser.CookieContainer.GetCookieValue(SteamCommunityURL, "sessionid"); if (string.IsNullOrEmpty(sessionID)) { - Logging.LogNullError(nameof(sessionID), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(sessionID)); return; } @@ -713,7 +714,7 @@ namespace ArchiSteamFarm { internal void DeclineTradeOffer(ulong tradeID) { if ((tradeID == 0) || string.IsNullOrEmpty(Bot.BotConfig.SteamApiKey)) { - Logging.LogNullError(nameof(tradeID) + " || " + nameof(Bot.BotConfig.SteamApiKey), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(tradeID) + " || " + nameof(Bot.BotConfig.SteamApiKey)); return; } @@ -729,13 +730,13 @@ namespace ArchiSteamFarm { secure: !Program.GlobalConfig.ForceHttp ); } catch (Exception e) { - Logging.LogGenericException(e, Bot.BotName); + Bot.ArchiLogger.LogGenericException(e); } } } if (response == null) { - Logging.LogGenericWarning("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); + Bot.ArchiLogger.LogGenericWarning("Request failed even after " + WebBrowser.MaxRetries + " tries"); } } @@ -761,13 +762,13 @@ namespace ArchiSteamFarm { foreach (JToken description in descriptions.Where(description => description != null)) { string classIDString = description["classid"]?.ToString(); if (string.IsNullOrEmpty(classIDString)) { - Logging.LogNullError(nameof(classIDString), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(classIDString)); continue; } ulong classID; if (!ulong.TryParse(classIDString, out classID) || (classID == 0)) { - Logging.LogNullError(nameof(classID), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(classID)); continue; } @@ -785,12 +786,12 @@ namespace ArchiSteamFarm { if (appID == 0) { string appIDString = description["appid"]?.ToString(); if (string.IsNullOrEmpty(appIDString)) { - Logging.LogNullError(nameof(appIDString), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(appIDString)); continue; } if (!uint.TryParse(appIDString, out appID) || (appID == 0)) { - Logging.LogNullError(nameof(appID), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(appID)); continue; } } @@ -807,7 +808,7 @@ namespace ArchiSteamFarm { IEnumerable items = jObject.SelectTokens("$.rgInventory.*"); if (items == null) { - Logging.LogNullError(nameof(items), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(items)); return null; } @@ -817,12 +818,12 @@ namespace ArchiSteamFarm { try { steamItem = item.ToObject(); } catch (JsonException e) { - Logging.LogGenericException(e, Bot.BotName); + Bot.ArchiLogger.LogGenericException(e); return null; } if (steamItem == null) { - Logging.LogNullError(nameof(steamItem), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(steamItem)); return null; } @@ -845,7 +846,7 @@ namespace ArchiSteamFarm { uint nextPage; if (!uint.TryParse(jObject["more_start"]?.ToString(), out nextPage) || (nextPage <= currentPage)) { - Logging.LogNullError(nameof(nextPage), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(nextPage)); return null; } @@ -857,7 +858,7 @@ namespace ArchiSteamFarm { internal async Task SendTradeOffer(HashSet inventory, ulong partnerID, string token = null) { if ((inventory == null) || (inventory.Count == 0) || (partnerID == 0)) { - Logging.LogNullError(nameof(inventory) + " || " + nameof(inventory.Count) + " || " + nameof(partnerID), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(inventory) + " || " + nameof(inventory.Count) + " || " + nameof(partnerID)); return false; } @@ -867,7 +868,7 @@ namespace ArchiSteamFarm { string sessionID = WebBrowser.CookieContainer.GetCookieValue(SteamCommunityURL, "sessionid"); if (string.IsNullOrEmpty(sessionID)) { - Logging.LogNullError(nameof(sessionID), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(sessionID)); return false; } @@ -910,7 +911,7 @@ namespace ArchiSteamFarm { internal async Task GetBadgePage(byte page) { if (page == 0) { - Logging.LogNullError(nameof(page), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(page)); return null; } @@ -924,7 +925,7 @@ namespace ArchiSteamFarm { internal async Task GetGameCardsPage(ulong appID) { if (appID == 0) { - Logging.LogNullError(nameof(appID), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(appID)); return null; } @@ -971,7 +972,7 @@ namespace ArchiSteamFarm { LastSessionRefreshCheck = DateTime.Now; return true; } else { - Logging.LogGenericInfo("Refreshing our session!", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Refreshing our session!"); return await Bot.RefreshSession().ConfigureAwait(false); } } finally { @@ -981,11 +982,11 @@ namespace ArchiSteamFarm { private async Task UnlockParentalAccount(string parentalPin) { if (string.IsNullOrEmpty(parentalPin)) { - Logging.LogNullError(nameof(parentalPin), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(parentalPin)); return false; } - Logging.LogGenericInfo("Unlocking parental account...", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Unlocking parental account..."); string request = SteamCommunityURL + "/parental/ajaxunlock"; Dictionary data = new Dictionary(1) { @@ -994,11 +995,11 @@ namespace ArchiSteamFarm { bool result = await WebBrowser.UrlPostRetry(request, data, SteamCommunityURL).ConfigureAwait(false); if (!result) { - Logging.LogGenericInfo("Failed!", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Failed!"); return false; } - Logging.LogGenericInfo("Success!", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Success!"); return true; } } diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 69fc76879..bbf7ea929 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -64,6 +64,7 @@ namespace ArchiSteamFarm { internal readonly string BotName; internal readonly ArchiHandler ArchiHandler; + internal readonly ArchiLogger ArchiLogger; internal readonly ArchiWebHandler ArchiWebHandler; private readonly string SentryFile; @@ -109,14 +110,14 @@ namespace ArchiSteamFarm { try { return JsonConvert.SerializeObject(response); } catch (JsonException e) { - Logging.LogGenericException(e); + ASF.ArchiLogger.LogGenericException(e); return null; } } internal static void InitializeCMs(uint cellID, IServerListProvider serverListProvider) { if (serverListProvider == null) { - Logging.LogNullError(nameof(serverListProvider)); + ASF.ArchiLogger.LogNullError(nameof(serverListProvider)); return; } @@ -129,7 +130,7 @@ namespace ArchiSteamFarm { return (steamID == Program.GlobalConfig.SteamOwnerID) || (Debugging.IsDebugBuild && (steamID == SharedInfo.ArchiSteamID)); } - Logging.LogNullError(nameof(steamID)); + ASF.ArchiLogger.LogNullError(nameof(steamID)); return false; } @@ -138,7 +139,7 @@ namespace ArchiSteamFarm { return Regex.IsMatch(key, @"^[0-9A-Z]{4,7}-[0-9A-Z]{4,7}-[0-9A-Z]{4,7}(?:(?:-[0-9A-Z]{4,7})?(?:-[0-9A-Z]{4,7}))?$", RegexOptions.IgnoreCase); } - Logging.LogNullError(nameof(key)); + ASF.ArchiLogger.LogNullError(nameof(key)); return false; } @@ -167,16 +168,17 @@ namespace ArchiSteamFarm { throw new ArgumentException("That bot is already defined!"); } - string botPath = Path.Combine(SharedInfo.ConfigDirectory, botName); - BotName = botName; - SentryFile = botPath + ".bin"; + ArchiLogger = new ArchiLogger(botName); + string botPath = Path.Combine(SharedInfo.ConfigDirectory, botName); string botConfigFile = botPath + ".json"; + SentryFile = botPath + ".bin"; + BotConfig = BotConfig.Load(botConfigFile); if (BotConfig == null) { - Logging.LogGenericError("Your bot config is invalid, please verify content of " + botConfigFile + " and try again!", botName); + ArchiLogger.LogGenericError("Your bot config is invalid, please verify content of " + botConfigFile + " and try again!"); return; } @@ -189,7 +191,7 @@ namespace ArchiSteamFarm { BotDatabase = BotDatabase.Load(botDatabaseFile); if (BotDatabase == null) { - Logging.LogGenericError("Bot database could not be loaded, refusing to create this bot instance! In order to recreate it, remove " + botDatabaseFile + " and try again!", botName); + ArchiLogger.LogGenericError("Bot database could not be loaded, refusing to create this bot instance! In order to recreate it, remove " + botDatabaseFile + " and try again!"); return; } @@ -207,17 +209,17 @@ namespace ArchiSteamFarm { SteamClient = new SteamClient(Program.GlobalConfig.SteamProtocol); if (Program.GlobalConfig.Debug && Directory.Exists(SharedInfo.DebugDirectory)) { - string debugListenerPath = Path.Combine(SharedInfo.DebugDirectory, botName); + string debugListenerPath = Path.Combine(SharedInfo.DebugDirectory); try { Directory.CreateDirectory(debugListenerPath); SteamClient.DebugNetworkListener = new NetHookNetworkListener(debugListenerPath); } catch (Exception e) { - Logging.LogGenericException(e, botName); + ArchiLogger.LogGenericException(e); } } - ArchiHandler = new ArchiHandler(this); + ArchiHandler = new ArchiHandler(ArchiLogger); SteamClient.AddHandler(ArchiHandler); CallbackManager = new CallbackManager(SteamClient); @@ -270,7 +272,7 @@ namespace ArchiSteamFarm { internal async Task OnNewConfigLoaded(ASF.BotConfigEventArgs args) { if (args == null) { - Logging.LogNullError(nameof(args), BotName); + ArchiLogger.LogNullError(nameof(args)); return; } @@ -341,7 +343,7 @@ namespace ArchiSteamFarm { private async Task Initialize() { if (!BotConfig.Enabled) { - Logging.LogGenericInfo("Not starting this instance because it's disabled in config file", BotName); + ArchiLogger.LogGenericInfo("Not starting this instance because it's disabled in config file"); return; } @@ -424,7 +426,7 @@ namespace ArchiSteamFarm { try { callback = await SteamUser.RequestWebAPIUserNonce(); } catch (Exception e) { - Logging.LogGenericException(e, BotName); + ArchiLogger.LogGenericException(e); await Connect(true).ConfigureAwait(false); return false; } @@ -447,7 +449,7 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericInfo("Stopping...", BotName); + ArchiLogger.LogGenericInfo("Stopping..."); KeepRunning = false; if (SteamClient.IsConnected) { @@ -488,7 +490,7 @@ namespace ArchiSteamFarm { internal async Task Response(ulong steamID, string message) { if ((steamID == 0) || string.IsNullOrEmpty(message)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(message), BotName); + ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(message)); return null; } @@ -637,7 +639,7 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericWarning("Connection to Steam Network lost, reconnecting...", BotName); + ArchiLogger.LogGenericWarning("Connection to Steam Network lost, reconnecting..."); Connect(true).Forget(); } } @@ -676,7 +678,7 @@ namespace ArchiSteamFarm { if (!KeepRunning) { KeepRunning = true; Task.Run(() => HandleCallbacks()).Forget(); - Logging.LogGenericInfo("Starting...", BotName); + ArchiLogger.LogGenericInfo("Starting..."); } await Connect().ConfigureAwait(false); @@ -687,18 +689,18 @@ namespace ArchiSteamFarm { return (steamID == BotConfig.SteamMasterID) || IsOwner(steamID); } - Logging.LogNullError(nameof(steamID), BotName); + ArchiLogger.LogNullError(nameof(steamID)); return false; } private void CheckOccupationStatus() { if (!IsFarmingPossible) { - Logging.LogGenericInfo("Account is currently being used, ASF will resume farming when it's free...", BotName); + ArchiLogger.LogGenericInfo("Account is currently being used, ASF will resume farming when it's free..."); StopFamilySharingInactivityTimer(); return; } - Logging.LogGenericInfo("Account is no longer occupied, farming process resumed!", BotName); + ArchiLogger.LogGenericInfo("Account is no longer occupied, farming process resumed!"); CardsFarmer.Resume(false); } @@ -707,7 +709,7 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericInfo("Shared library has not been launched in given time period, farming process resumed!", BotName); + ArchiLogger.LogGenericInfo("Shared library has not been launched in given time period, farming process resumed!"); CardsFarmer.Resume(false); } @@ -748,26 +750,26 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericInfo("Converting .maFile into ASF format...", BotName); + ArchiLogger.LogGenericInfo("Converting .maFile into ASF format..."); try { BotDatabase.MobileAuthenticator = JsonConvert.DeserializeObject(File.ReadAllText(maFilePath)); File.Delete(maFilePath); } catch (Exception e) { - Logging.LogGenericException(e, BotName); + ArchiLogger.LogGenericException(e); return; } if (BotDatabase.MobileAuthenticator == null) { - Logging.LogNullError(nameof(BotDatabase.MobileAuthenticator), BotName); + ArchiLogger.LogNullError(nameof(BotDatabase.MobileAuthenticator)); return; } BotDatabase.MobileAuthenticator.Init(this); if (!BotDatabase.MobileAuthenticator.HasCorrectDeviceID) { - Logging.LogGenericWarning("Your DeviceID is incorrect or doesn't exist", BotName); - string deviceID = Program.GetUserInput(SharedInfo.EUserInputType.DeviceID, BotName); + ArchiLogger.LogGenericWarning("Your DeviceID is incorrect or doesn't exist"); + string deviceID = Program.GetUserInput(SharedInfo.EUserInputType.DeviceID); if (string.IsNullOrEmpty(deviceID)) { BotDatabase.MobileAuthenticator = null; return; @@ -777,12 +779,12 @@ namespace ArchiSteamFarm { BotDatabase.Save(); } - Logging.LogGenericInfo("Successfully finished importing mobile authenticator!", BotName); + ArchiLogger.LogGenericInfo("Successfully finished importing mobile authenticator!"); } private string ResponsePassword(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID), BotName); + ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -801,7 +803,7 @@ namespace ArchiSteamFarm { private static string ResponsePassword(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(botName)); + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -819,7 +821,7 @@ namespace ArchiSteamFarm { private async Task ResponsePause(ulong steamID, bool sticky) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID), BotName); + ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -847,7 +849,7 @@ namespace ArchiSteamFarm { private static async Task ResponsePause(ulong steamID, string botName, bool sticky) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(botName)); + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -865,7 +867,7 @@ namespace ArchiSteamFarm { private string ResponseResume(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID), BotName); + ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -888,7 +890,7 @@ namespace ArchiSteamFarm { private static string ResponseResume(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(botName)); + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -906,7 +908,7 @@ namespace ArchiSteamFarm { private string ResponseStatus(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID), BotName); + ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -949,7 +951,7 @@ namespace ArchiSteamFarm { private static string ResponseStatus(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(botName)); + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -967,7 +969,7 @@ namespace ArchiSteamFarm { private static string ResponseStatusAll(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID)); + ASF.ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -985,7 +987,7 @@ namespace ArchiSteamFarm { private async Task ResponseLoot(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID), BotName); + ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -1030,7 +1032,7 @@ namespace ArchiSteamFarm { private static async Task ResponseLoot(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(botName)); + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -1048,7 +1050,7 @@ namespace ArchiSteamFarm { private static async Task ResponseLootAll(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID)); + ASF.ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -1062,7 +1064,7 @@ namespace ArchiSteamFarm { private async Task Response2FA(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID), BotName); + ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -1084,7 +1086,7 @@ namespace ArchiSteamFarm { private static async Task Response2FA(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(botName)); + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -1102,7 +1104,7 @@ namespace ArchiSteamFarm { private async Task Response2FAConfirm(ulong steamID, bool confirm) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID), BotName); + ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -1123,7 +1125,7 @@ namespace ArchiSteamFarm { private static async Task Response2FAConfirm(ulong steamID, string botName, bool confirm) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(botName)); + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -1144,13 +1146,13 @@ namespace ArchiSteamFarm { return !IsOwner(steamID) ? null : GetAPIStatus(); } - Logging.LogNullError(nameof(steamID)); + ASF.ArchiLogger.LogNullError(nameof(steamID)); return null; } private static string ResponseExit(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID)); + ASF.ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -1169,7 +1171,7 @@ namespace ArchiSteamFarm { private async Task ResponseFarm(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID), BotName); + ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -1188,7 +1190,7 @@ namespace ArchiSteamFarm { private static async Task ResponseFarm(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(botName)); + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -1206,7 +1208,7 @@ namespace ArchiSteamFarm { private string ResponseHelp(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID), BotName); + ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -1220,7 +1222,7 @@ namespace ArchiSteamFarm { [SuppressMessage("ReSharper", "FunctionComplexityOverflow")] private async Task ResponseRedeem(ulong steamID, string message, ERedeemFlags redeemFlags = ERedeemFlags.None) { if ((steamID == 0) || string.IsNullOrEmpty(message)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(message), BotName); + ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(message)); return null; } @@ -1344,7 +1346,7 @@ namespace ArchiSteamFarm { private static async Task ResponseRedeem(ulong steamID, string botName, string message, ERedeemFlags redeemFlags = ERedeemFlags.None) { if ((steamID == 0) || string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(message)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(botName) + " || " + nameof(message)); + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName) + " || " + nameof(message)); return null; } @@ -1362,7 +1364,7 @@ namespace ArchiSteamFarm { private static string ResponseRejoinChat(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID)); + ASF.ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -1379,7 +1381,7 @@ namespace ArchiSteamFarm { private static string ResponseRestart(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID)); + ASF.ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -1398,7 +1400,7 @@ namespace ArchiSteamFarm { private static string ResponseStartAll(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID)); + ASF.ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -1415,7 +1417,7 @@ namespace ArchiSteamFarm { private async Task ResponseAddLicense(ulong steamID, ICollection gameIDs) { if ((steamID == 0) || (gameIDs == null) || (gameIDs.Count == 0)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(gameIDs) + " || " + nameof(gameIDs.Count), BotName); + ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(gameIDs) + " || " + nameof(gameIDs.Count)); return null; } @@ -1443,7 +1445,7 @@ namespace ArchiSteamFarm { private static async Task ResponseAddLicense(ulong steamID, string botName, string games) { if ((steamID == 0) || string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(games)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(botName) + " || " + nameof(games)); + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName) + " || " + nameof(games)); return null; } @@ -1477,7 +1479,7 @@ namespace ArchiSteamFarm { private async Task ResponseOwns(ulong steamID, string query) { if ((steamID == 0) || string.IsNullOrEmpty(query)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(query), BotName); + ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(query)); return null; } @@ -1532,7 +1534,7 @@ namespace ArchiSteamFarm { private static async Task ResponseOwns(ulong steamID, string botName, string query) { if ((steamID == 0) || string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(query)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(botName) + " || " + nameof(query)); + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName) + " || " + nameof(query)); return null; } @@ -1550,7 +1552,7 @@ namespace ArchiSteamFarm { private static async Task ResponseOwnsAll(ulong steamID, string query) { if ((steamID == 0) || string.IsNullOrEmpty(query)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(query)); + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(query)); return null; } @@ -1570,7 +1572,7 @@ namespace ArchiSteamFarm { private async Task ResponsePlay(ulong steamID, HashSet gameIDs) { if ((steamID == 0) || (gameIDs == null) || (gameIDs.Count == 0)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(gameIDs) + " || " + nameof(gameIDs.Count), BotName); + ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(gameIDs) + " || " + nameof(gameIDs.Count)); return null; } @@ -1592,7 +1594,7 @@ namespace ArchiSteamFarm { private static async Task ResponsePlay(ulong steamID, string botName, string games) { if ((steamID == 0) || string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(games)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(botName) + " || " + nameof(games)); + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName) + " || " + nameof(games)); return null; } @@ -1630,7 +1632,7 @@ namespace ArchiSteamFarm { private string ResponseStart(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID), BotName); + ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -1649,7 +1651,7 @@ namespace ArchiSteamFarm { private static string ResponseStart(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(botName)); + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -1667,7 +1669,7 @@ namespace ArchiSteamFarm { private string ResponseStop(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID), BotName); + ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -1685,7 +1687,7 @@ namespace ArchiSteamFarm { private static string ResponseStop(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(botName)); + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -1706,13 +1708,13 @@ namespace ArchiSteamFarm { return !IsMaster(steamID) ? null : "ERROR: Unknown command!"; } - Logging.LogNullError(nameof(steamID), BotName); + ArchiLogger.LogNullError(nameof(steamID)); return null; } private static async Task ResponseUpdate(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID)); + ASF.ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -1726,7 +1728,7 @@ namespace ArchiSteamFarm { private string ResponseVersion(ulong steamID) { if (steamID == 0) { - Logging.LogNullError(nameof(steamID), BotName); + ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -1747,7 +1749,7 @@ namespace ArchiSteamFarm { try { CallbackManager.RunWaitCallbacks(timeSpan); } catch (Exception e) { - Logging.LogGenericException(e, BotName); + ArchiLogger.LogGenericException(e); } finally { CallbackSemaphore.Release(); } @@ -1756,7 +1758,7 @@ namespace ArchiSteamFarm { private async Task HandleMessage(ulong chatID, ulong steamID, string message) { if ((chatID == 0) || (steamID == 0) || string.IsNullOrEmpty(message)) { - Logging.LogNullError(nameof(chatID) + " || " + nameof(steamID) + " || " + nameof(message), BotName); + ArchiLogger.LogNullError(nameof(chatID) + " || " + nameof(steamID) + " || " + nameof(message)); return; } @@ -1770,7 +1772,7 @@ namespace ArchiSteamFarm { private void SendMessage(ulong steamID, string message) { if ((steamID == 0) || string.IsNullOrEmpty(message)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(message), BotName); + ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(message)); return; } @@ -1783,7 +1785,7 @@ namespace ArchiSteamFarm { private void SendMessageToChannel(ulong steamID, string message) { if ((steamID == 0) || string.IsNullOrEmpty(message)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(message), BotName); + ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(message)); return; } @@ -1799,7 +1801,7 @@ namespace ArchiSteamFarm { private void SendMessageToUser(ulong steamID, string message) { if ((steamID == 0) || string.IsNullOrEmpty(message)) { - Logging.LogNullError(nameof(steamID) + " || " + nameof(message), BotName); + ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(message)); return; } @@ -1823,7 +1825,7 @@ namespace ArchiSteamFarm { private bool InitializeLoginAndPassword(bool requiresPassword) { if (string.IsNullOrEmpty(BotConfig.SteamLogin)) { - BotConfig.SteamLogin = Program.GetUserInput(SharedInfo.EUserInputType.Login, BotName); + BotConfig.SteamLogin = Program.GetUserInput(SharedInfo.EUserInputType.Login); if (string.IsNullOrEmpty(BotConfig.SteamLogin)) { return false; } @@ -1833,7 +1835,7 @@ namespace ArchiSteamFarm { return true; } - BotConfig.SteamPassword = Program.GetUserInput(SharedInfo.EUserInputType.Password, BotName); + BotConfig.SteamPassword = Program.GetUserInput(SharedInfo.EUserInputType.Password); return !string.IsNullOrEmpty(BotConfig.SteamPassword); } @@ -1847,19 +1849,19 @@ namespace ArchiSteamFarm { private void OnConnected(SteamClient.ConnectedCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback), BotName); + ArchiLogger.LogNullError(nameof(callback)); return; } if (callback.Result != EResult.OK) { - Logging.LogGenericError("Unable to connect to Steam: " + callback.Result, BotName); + ArchiLogger.LogGenericError("Unable to connect to Steam: " + callback.Result); return; } - Logging.LogGenericInfo("Connected to Steam!", BotName); + ArchiLogger.LogGenericInfo("Connected to Steam!"); if (!KeepRunning) { - Logging.LogGenericInfo("Disconnecting...", BotName); + ArchiLogger.LogGenericInfo("Disconnecting..."); Disconnect(); return; } @@ -1870,7 +1872,7 @@ namespace ArchiSteamFarm { byte[] sentryFileContent = File.ReadAllBytes(SentryFile); sentryFileHash = SteamKit2.CryptoHelper.SHAHash(sentryFileContent); } catch (Exception e) { - Logging.LogGenericException(e, BotName); + ArchiLogger.LogGenericException(e); } } @@ -1879,7 +1881,7 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericInfo("Logging in...", BotName); + ArchiLogger.LogGenericInfo("Logging in..."); string password = BotConfig.SteamPassword; if (!string.IsNullOrEmpty(password)) { @@ -1916,14 +1918,14 @@ namespace ArchiSteamFarm { private async void OnDisconnected(SteamClient.DisconnectedCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback), BotName); + ArchiLogger.LogNullError(nameof(callback)); return; } EResult lastLogOnResult = LastLogOnResult; LastLogOnResult = EResult.Invalid; - Logging.LogGenericInfo("Disconnected from Steam!", BotName); + ArchiLogger.LogGenericInfo("Disconnected from Steam!"); ArchiWebHandler.OnDisconnected(); CardsFarmer.OnDisconnected(); @@ -1950,7 +1952,7 @@ namespace ArchiSteamFarm { } BotDatabase.LoginKey = null; - Logging.LogGenericInfo("Removed expired login key", BotName); + ArchiLogger.LogGenericInfo("Removed expired login key"); break; case EResult.NoConnection: case EResult.ServiceUnavailable: @@ -1959,7 +1961,7 @@ namespace ArchiSteamFarm { await Task.Delay(5000).ConfigureAwait(false); break; case EResult.RateLimitExceeded: - Logging.LogGenericInfo("Will retry after 25 minutes...", BotName); + ArchiLogger.LogGenericInfo("Will retry after 25 minutes..."); await Task.Delay(25 * 60 * 1000).ConfigureAwait(false); // Captcha disappears after around 20 minutes, so we make it 25 break; } @@ -1968,19 +1970,19 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericInfo("Reconnecting...", BotName); + ArchiLogger.LogGenericInfo("Reconnecting..."); await Connect().ConfigureAwait(false); } private void OnFreeLicense(SteamApps.FreeLicenseCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback), BotName); + ArchiLogger.LogNullError(nameof(callback)); } } private async void OnGuestPassList(SteamApps.GuestPassListCallback callback) { if (callback?.GuestPasses == null) { - Logging.LogNullError(nameof(callback) + " || " + nameof(callback.GuestPasses), BotName); + ArchiLogger.LogNullError(nameof(callback) + " || " + nameof(callback.GuestPasses)); return; } @@ -1991,25 +1993,25 @@ namespace ArchiSteamFarm { foreach (ulong gid in callback.GuestPasses.Select(guestPass => guestPass["gid"].AsUnsignedLong()).Where(gid => (gid != 0) && !HandledGifts.Contains(gid))) { HandledGifts.Add(gid); - Logging.LogGenericInfo("Accepting gift: " + gid + "...", BotName); + ArchiLogger.LogGenericInfo("Accepting gift: " + gid + "..."); await LimitGiftsRequestsAsync().ConfigureAwait(false); ArchiHandler.RedeemGuestPassResponseCallback response = await ArchiHandler.RedeemGuestPass(gid).ConfigureAwait(false); if (response != null) { if (response.Result == EResult.OK) { - Logging.LogGenericInfo("Success!", BotName); + ArchiLogger.LogGenericInfo("Success!"); } else { - Logging.LogGenericWarning("Failed with error: " + response.Result, BotName); + ArchiLogger.LogGenericWarning("Failed with error: " + response.Result); } } else { - Logging.LogGenericWarning("Failed!", BotName); + ArchiLogger.LogGenericWarning("Failed!"); } } } private async void OnLicenseList(SteamApps.LicenseListCallback callback) { if (callback?.LicenseList == null) { - Logging.LogNullError(nameof(callback) + " || " + nameof(callback.LicenseList), BotName); + ArchiLogger.LogNullError(nameof(callback) + " || " + nameof(callback.LicenseList)); return; } @@ -2038,7 +2040,7 @@ namespace ArchiSteamFarm { private void OnChatInvite(SteamFriends.ChatInviteCallback callback) { if ((callback?.ChatRoomID == null) || (callback.PatronID == null)) { - Logging.LogNullError(nameof(callback) + " || " + nameof(callback.ChatRoomID) + " || " + nameof(callback.PatronID), BotName); + ArchiLogger.LogNullError(nameof(callback) + " || " + nameof(callback.ChatRoomID) + " || " + nameof(callback.PatronID)); return; } @@ -2051,7 +2053,7 @@ namespace ArchiSteamFarm { private async void OnChatMsg(SteamFriends.ChatMsgCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback), BotName); + ArchiLogger.LogNullError(nameof(callback)); return; } @@ -2060,7 +2062,7 @@ namespace ArchiSteamFarm { } if ((callback.ChatRoomID == null) || (callback.ChatterID == null) || string.IsNullOrEmpty(callback.Message)) { - Logging.LogNullError(nameof(callback.ChatRoomID) + " || " + nameof(callback.ChatterID) + " || " + nameof(callback.Message), BotName); + ArchiLogger.LogNullError(nameof(callback.ChatRoomID) + " || " + nameof(callback.ChatterID) + " || " + nameof(callback.Message)); return; } @@ -2080,7 +2082,7 @@ namespace ArchiSteamFarm { private void OnFriendsList(SteamFriends.FriendsListCallback callback) { if (callback?.FriendList == null) { - Logging.LogNullError(nameof(callback) + " || " + nameof(callback.FriendList), BotName); + ArchiLogger.LogNullError(nameof(callback) + " || " + nameof(callback.FriendList)); return; } @@ -2095,7 +2097,7 @@ namespace ArchiSteamFarm { private async void OnFriendMsg(SteamFriends.FriendMsgCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback), BotName); + ArchiLogger.LogNullError(nameof(callback)); return; } @@ -2104,7 +2106,7 @@ namespace ArchiSteamFarm { } if ((callback.Sender == null) || string.IsNullOrEmpty(callback.Message)) { - Logging.LogNullError(nameof(callback.Sender) + " || " + nameof(callback.Message), BotName); + ArchiLogger.LogNullError(nameof(callback.Sender) + " || " + nameof(callback.Message)); return; } @@ -2113,7 +2115,7 @@ namespace ArchiSteamFarm { private async void OnFriendMsgHistory(SteamFriends.FriendMsgHistoryCallback callback) { if ((callback?.Messages == null) || (callback.SteamID == null)) { - Logging.LogNullError(nameof(callback) + " || " + nameof(callback.Messages) + " || " + nameof(callback.SteamID), BotName); + ArchiLogger.LogNullError(nameof(callback) + " || " + nameof(callback.Messages) + " || " + nameof(callback.SteamID)); return; } @@ -2140,7 +2142,7 @@ namespace ArchiSteamFarm { private void OnPersonaState(SteamFriends.PersonaStateCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback), BotName); + ArchiLogger.LogNullError(nameof(callback)); return; } @@ -2154,7 +2156,7 @@ namespace ArchiSteamFarm { private void OnAccountInfo(SteamUser.AccountInfoCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback), BotName); + ArchiLogger.LogNullError(nameof(callback)); return; } @@ -2165,15 +2167,15 @@ namespace ArchiSteamFarm { private void OnLoggedOff(SteamUser.LoggedOffCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback), BotName); + ArchiLogger.LogNullError(nameof(callback)); return; } - Logging.LogGenericInfo("Logged off of Steam: " + callback.Result, BotName); + ArchiLogger.LogGenericInfo("Logged off of Steam: " + callback.Result); switch (callback.Result) { case EResult.LogonSessionReplaced: - Logging.LogGenericError("This account seems to be used in another ASF instance, which is undefined behaviour, refusing to keep it running!", BotName); + ArchiLogger.LogGenericError("This account seems to be used in another ASF instance, which is undefined behaviour, refusing to keep it running!"); Stop(); break; } @@ -2181,7 +2183,7 @@ namespace ArchiSteamFarm { private async void OnLoggedOn(SteamUser.LoggedOnCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback), BotName); + ArchiLogger.LogNullError(nameof(callback)); return; } @@ -2193,7 +2195,7 @@ namespace ArchiSteamFarm { switch (callback.Result) { case EResult.AccountLogonDenied: - AuthCode = Program.GetUserInput(SharedInfo.EUserInputType.SteamGuard, BotName); + AuthCode = Program.GetUserInput(SharedInfo.EUserInputType.SteamGuard); if (string.IsNullOrEmpty(AuthCode)) { Stop(); } @@ -2201,17 +2203,17 @@ namespace ArchiSteamFarm { break; case EResult.AccountLoginDeniedNeedTwoFactor: if (BotDatabase.MobileAuthenticator == null) { - TwoFactorCode = Program.GetUserInput(SharedInfo.EUserInputType.TwoFactorAuthentication, BotName); + TwoFactorCode = Program.GetUserInput(SharedInfo.EUserInputType.TwoFactorAuthentication); if (string.IsNullOrEmpty(TwoFactorCode)) { Stop(); } } else { - Logging.LogGenericWarning("2FA code was invalid despite of using ASF 2FA. Invalid authenticator or bad timing?", BotName); + ArchiLogger.LogGenericWarning("2FA code was invalid despite of using ASF 2FA. Invalid authenticator or bad timing?"); } break; case EResult.OK: - Logging.LogGenericInfo("Successfully logged on!", BotName); + ArchiLogger.LogGenericInfo("Successfully logged on!"); // Old status for these doesn't matter, we'll be notified in callback if needed LibraryLockedBySteamID = 0; @@ -2230,7 +2232,7 @@ namespace ArchiSteamFarm { } if (string.IsNullOrEmpty(BotConfig.SteamParentalPIN)) { - BotConfig.SteamParentalPIN = Program.GetUserInput(SharedInfo.EUserInputType.SteamParentalPIN, BotName); + BotConfig.SteamParentalPIN = Program.GetUserInput(SharedInfo.EUserInputType.SteamParentalPIN); if (string.IsNullOrEmpty(BotConfig.SteamParentalPIN)) { Stop(); return; @@ -2269,10 +2271,10 @@ namespace ArchiSteamFarm { case EResult.Timeout: case EResult.TryAnotherCM: case EResult.TwoFactorCodeMismatch: - Logging.LogGenericWarning("Unable to login to Steam: " + callback.Result + " / " + callback.ExtendedResult, BotName); + ArchiLogger.LogGenericWarning("Unable to login to Steam: " + callback.Result + " / " + callback.ExtendedResult); break; default: // Unexpected result, shutdown immediately - Logging.LogGenericError("Unable to login to Steam: " + callback.Result + " / " + callback.ExtendedResult, BotName); + ArchiLogger.LogGenericError("Unable to login to Steam: " + callback.Result + " / " + callback.ExtendedResult); Stop(); break; } @@ -2280,7 +2282,7 @@ namespace ArchiSteamFarm { private void OnLoginKey(SteamUser.LoginKeyCallback callback) { if (string.IsNullOrEmpty(callback?.LoginKey)) { - Logging.LogNullError(nameof(callback) + " || " + nameof(callback.LoginKey), BotName); + ArchiLogger.LogNullError(nameof(callback) + " || " + nameof(callback.LoginKey)); return; } @@ -2295,7 +2297,7 @@ namespace ArchiSteamFarm { private void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback), BotName); + ArchiLogger.LogNullError(nameof(callback)); return; } @@ -2314,7 +2316,7 @@ namespace ArchiSteamFarm { } } } catch (Exception e) { - Logging.LogGenericException(e, BotName); + ArchiLogger.LogGenericException(e); return; } @@ -2334,13 +2336,13 @@ namespace ArchiSteamFarm { private void OnWebAPIUserNonce(SteamUser.WebAPIUserNonceCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback), BotName); + ArchiLogger.LogNullError(nameof(callback)); } } private void OnNotifications(ArchiHandler.NotificationsCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback), BotName); + ArchiLogger.LogNullError(nameof(callback)); return; } @@ -2365,7 +2367,7 @@ namespace ArchiSteamFarm { private void OnOfflineMessage(ArchiHandler.OfflineMessageCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback), BotName); + ArchiLogger.LogNullError(nameof(callback)); return; } @@ -2378,7 +2380,7 @@ namespace ArchiSteamFarm { private void OnPlayingSessionState(ArchiHandler.PlayingSessionStateCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback), BotName); + ArchiLogger.LogNullError(nameof(callback)); return; } @@ -2392,13 +2394,13 @@ namespace ArchiSteamFarm { private void OnPurchaseResponse(ArchiHandler.PurchaseResponseCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback), BotName); + ArchiLogger.LogNullError(nameof(callback)); } } private void OnSharedLibraryLockStatus(ArchiHandler.SharedLibraryLockStatusCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback), BotName); + ArchiLogger.LogNullError(nameof(callback)); return; } diff --git a/ArchiSteamFarm/BotConfig.cs b/ArchiSteamFarm/BotConfig.cs index e9d1572d2..fcc774e8d 100644 --- a/ArchiSteamFarm/BotConfig.cs +++ b/ArchiSteamFarm/BotConfig.cs @@ -139,7 +139,7 @@ namespace ArchiSteamFarm { internal static BotConfig Load(string filePath) { if (string.IsNullOrEmpty(filePath)) { - Logging.LogNullError(nameof(filePath)); + ASF.ArchiLogger.LogNullError(nameof(filePath)); return null; } @@ -152,12 +152,12 @@ namespace ArchiSteamFarm { try { botConfig = JsonConvert.DeserializeObject(File.ReadAllText(filePath)); } catch (Exception e) { - Logging.LogGenericException(e); + ASF.ArchiLogger.LogGenericException(e); return null; } if (botConfig == null) { - Logging.LogNullError(nameof(botConfig)); + ASF.ArchiLogger.LogNullError(nameof(botConfig)); return null; } @@ -173,7 +173,7 @@ namespace ArchiSteamFarm { return botConfig; } - Logging.LogGenericWarning("Playing more than " + CardsFarmer.MaxGamesPlayedConcurrently + " games concurrently is not possible, only first " + CardsFarmer.MaxGamesPlayedConcurrently + " entries from GamesPlayedWhileIdle will be used"); + ASF.ArchiLogger.LogGenericWarning("Playing more than " + CardsFarmer.MaxGamesPlayedConcurrently + " games concurrently is not possible, only first " + CardsFarmer.MaxGamesPlayedConcurrently + " entries from GamesPlayedWhileIdle will be used"); HashSet validGames = new HashSet(botConfig.GamesPlayedWhileIdle.Take(CardsFarmer.MaxGamesPlayedConcurrently)); botConfig.GamesPlayedWhileIdle.IntersectWith(validGames); diff --git a/ArchiSteamFarm/BotDatabase.cs b/ArchiSteamFarm/BotDatabase.cs index 6b1ea6b0f..a9c642a9a 100644 --- a/ArchiSteamFarm/BotDatabase.cs +++ b/ArchiSteamFarm/BotDatabase.cs @@ -72,7 +72,7 @@ namespace ArchiSteamFarm { internal static BotDatabase Load(string filePath) { if (string.IsNullOrEmpty(filePath)) { - Logging.LogNullError(nameof(filePath)); + ASF.ArchiLogger.LogNullError(nameof(filePath)); return null; } @@ -85,12 +85,12 @@ namespace ArchiSteamFarm { try { botDatabase = JsonConvert.DeserializeObject(File.ReadAllText(filePath)); } catch (Exception e) { - Logging.LogGenericException(e); + ASF.ArchiLogger.LogGenericException(e); return null; } if (botDatabase == null) { - Logging.LogNullError(nameof(botDatabase)); + ASF.ArchiLogger.LogNullError(nameof(botDatabase)); return null; } @@ -115,7 +115,7 @@ namespace ArchiSteamFarm { internal void Save() { string json = JsonConvert.SerializeObject(this); if (string.IsNullOrEmpty(json)) { - Logging.LogNullError(nameof(json)); + ASF.ArchiLogger.LogNullError(nameof(json)); return; } @@ -125,7 +125,7 @@ namespace ArchiSteamFarm { File.WriteAllText(FilePath, json); break; } catch (Exception e) { - Logging.LogGenericException(e); + ASF.ArchiLogger.LogGenericException(e); } Thread.Sleep(1000); diff --git a/ArchiSteamFarm/CardsFarmer.cs b/ArchiSteamFarm/CardsFarmer.cs index c6113369c..67dbde59a 100755 --- a/ArchiSteamFarm/CardsFarmer.cs +++ b/ArchiSteamFarm/CardsFarmer.cs @@ -129,7 +129,7 @@ namespace ArchiSteamFarm { internal void Resume(bool userAction) { if (StickyPause) { if (!userAction) { - Logging.LogGenericInfo("Not honoring this request, as sticky pause is enabled!", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Not honoring this request, as sticky pause is enabled!"); return; } @@ -155,16 +155,16 @@ namespace ArchiSteamFarm { } if (!await IsAnythingToFarm().ConfigureAwait(false)) { - Logging.LogGenericInfo("We don't have anything to farm on this account!", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("We don't have anything to farm on this account!"); await Bot.OnFarmingFinished(false).ConfigureAwait(false); return; } - Logging.LogGenericInfo("We have a total of " + GamesToFarm.Count + " games (" + GamesToFarm.Sum(game => game.CardsRemaining) + " cards) to farm on this account...", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("We have a total of " + GamesToFarm.Count + " games (" + GamesToFarm.Sum(game => game.CardsRemaining) + " cards) to farm on this account..."); // This is the last moment for final check if we can farm if (!Bot.IsFarmingPossible) { - Logging.LogGenericInfo("But account is currently occupied, so farming is stopped!", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("But account is currently occupied, so farming is stopped!"); return; } @@ -176,7 +176,7 @@ namespace ArchiSteamFarm { do { // Now the algorithm used for farming depends on whether account is restricted or not if (Bot.BotConfig.CardDropsRestricted) { // If we have restricted card drops, we use complex algorithm - Logging.LogGenericInfo("Chosen farming algorithm: Complex", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Chosen farming algorithm: Complex"); while (GamesToFarm.Count > 0) { HashSet gamesToFarmSolo = GamesToFarm.Count > 1 ? new HashSet(GamesToFarm.Where(game => game.HoursPlayed >= 2)) : new HashSet(GamesToFarm); if (gamesToFarmSolo.Count > 0) { @@ -191,7 +191,7 @@ namespace ArchiSteamFarm { } } else { if (FarmMultiple(GamesToFarm.OrderByDescending(game => game.HoursPlayed).Take(MaxGamesPlayedConcurrently))) { - Logging.LogGenericInfo("Done farming: " + string.Join(", ", GamesToFarm.Select(game => game.AppID)), Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Done farming: " + string.Join(", ", GamesToFarm.Select(game => game.AppID))); } else { NowFarming = false; return; @@ -199,7 +199,7 @@ namespace ArchiSteamFarm { } } } else { // If we have unrestricted card drops, we use simple algorithm - Logging.LogGenericInfo("Chosen farming algorithm: Simple", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Chosen farming algorithm: Simple"); while (GamesToFarm.Count > 0) { Game game = GamesToFarm.First(); if (await FarmSolo(game).ConfigureAwait(false)) { @@ -215,7 +215,7 @@ namespace ArchiSteamFarm { CurrentGamesFarming.ClearAndTrim(); NowFarming = false; - Logging.LogGenericInfo("Farming finished!", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Farming finished!"); await Bot.OnFarmingFinished(true).ConfigureAwait(false); } @@ -231,20 +231,20 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericInfo("Sending signal to stop farming", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Sending signal to stop farming"); KeepFarming = false; FarmResetEvent.Set(); - Logging.LogGenericInfo("Waiting for reaction...", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Waiting for reaction..."); for (byte i = 0; (i < 5) && NowFarming; i++) { await Task.Delay(1000).ConfigureAwait(false); } if (NowFarming) { - Logging.LogGenericWarning("Timed out!", Bot.BotName); + Bot.ArchiLogger.LogGenericWarning("Timed out!"); } - Logging.LogGenericInfo("Farming stopped!", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Farming stopped!"); Bot.OnFarmingStopped(); } finally { FarmingSemaphore.Release(); @@ -280,13 +280,13 @@ namespace ArchiSteamFarm { } private async Task IsAnythingToFarm() { - Logging.LogGenericInfo("Checking badges...", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Checking badges..."); // Find the number of badge pages - Logging.LogGenericInfo("Checking first page...", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Checking first page..."); HtmlDocument htmlDocument = await Bot.ArchiWebHandler.GetBadgePage(1).ConfigureAwait(false); if (htmlDocument == null) { - Logging.LogGenericWarning("Could not get badges information, will try again later!", Bot.BotName); + Bot.ArchiLogger.LogGenericWarning("Could not get badges information, will try again later!"); return false; } @@ -296,12 +296,12 @@ namespace ArchiSteamFarm { if (htmlNode != null) { string lastPage = htmlNode.InnerText; if (string.IsNullOrEmpty(lastPage)) { - Logging.LogNullError(nameof(lastPage), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(lastPage)); return false; } if (!byte.TryParse(lastPage, out maxPages) || (maxPages == 0)) { - Logging.LogNullError(nameof(maxPages), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(maxPages)); return false; } } @@ -314,7 +314,7 @@ namespace ArchiSteamFarm { return GamesToFarm.Count > 0; } - Logging.LogGenericInfo("Checking other pages...", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Checking other pages..."); List tasks = new List(maxPages - 1); for (byte page = 2; page <= maxPages; page++) { @@ -357,7 +357,7 @@ namespace ArchiSteamFarm { gamesToFarm = GamesToFarm.OrderByDescending(game => game.GameName); break; default: - Logging.LogGenericError("Unhandled case: " + Bot.BotConfig.FarmingOrder, Bot.BotName); + Bot.ArchiLogger.LogGenericError("Unhandled case: " + Bot.BotConfig.FarmingOrder); return; } @@ -366,7 +366,7 @@ namespace ArchiSteamFarm { private void CheckPage(HtmlDocument htmlDocument) { if (htmlDocument == null) { - Logging.LogNullError(nameof(htmlDocument), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(htmlDocument)); return; } @@ -389,19 +389,19 @@ namespace ArchiSteamFarm { // AppIDs string steamLink = farmingNode.GetAttributeValue("href", null); if (string.IsNullOrEmpty(steamLink)) { - Logging.LogNullError(nameof(steamLink), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(steamLink)); return; } int index = steamLink.LastIndexOf('/'); if (index < 0) { - Logging.LogNullError(nameof(index), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(index)); return; } index++; if (steamLink.Length <= index) { - Logging.LogNullError(nameof(steamLink.Length), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(steamLink.Length)); return; } @@ -409,7 +409,7 @@ namespace ArchiSteamFarm { uint appID; if (!uint.TryParse(steamLink, out appID) || (appID == 0)) { - Logging.LogNullError(nameof(appID), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(appID)); return; } @@ -420,13 +420,13 @@ namespace ArchiSteamFarm { // Hours HtmlNode timeNode = htmlNode.SelectSingleNode(".//div[@class='badge_title_stats_playtime']"); if (timeNode == null) { - Logging.LogNullError(nameof(timeNode), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(timeNode)); return; } string hoursString = timeNode.InnerText; if (string.IsNullOrEmpty(hoursString)) { - Logging.LogNullError(nameof(hoursString), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(hoursString)); return; } @@ -435,7 +435,7 @@ namespace ArchiSteamFarm { Match hoursMatch = Regex.Match(hoursString, @"[0-9\.,]+"); if (hoursMatch.Success) { // Might fail if we have 0.0 hours played if (!float.TryParse(hoursMatch.Value, NumberStyles.Number, CultureInfo.InvariantCulture, out hours)) { - Logging.LogNullError(nameof(hours), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(hours)); return; } } @@ -443,38 +443,38 @@ namespace ArchiSteamFarm { // Cards string progress = progressNode.InnerText; if (string.IsNullOrEmpty(progress)) { - Logging.LogNullError(nameof(progress), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(progress)); return; } Match progressMatch = Regex.Match(progress, @"\d+"); if (!progressMatch.Success) { - Logging.LogNullError(nameof(progressMatch), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(progressMatch)); return; } ushort cardsRemaining; if (!ushort.TryParse(progressMatch.Value, out cardsRemaining) || (cardsRemaining == 0)) { - Logging.LogNullError(nameof(cardsRemaining), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(cardsRemaining)); return; } // Names HtmlNode nameNode = htmlNode.SelectSingleNode("(.//div[@class='card_drop_info_body'])[last()]"); if (nameNode == null) { - Logging.LogNullError(nameof(nameNode), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(nameNode)); return; } string name = nameNode.InnerText; if (string.IsNullOrEmpty(name)) { - Logging.LogNullError(nameof(name), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(name)); return; } int nameStartIndex = name.IndexOf(" by playing ", StringComparison.Ordinal); if (nameStartIndex <= 0) { - Logging.LogNullError(nameof(nameStartIndex)); + Bot.ArchiLogger.LogNullError(nameof(nameStartIndex)); return; } @@ -482,7 +482,7 @@ namespace ArchiSteamFarm { int nameEndIndex = name.LastIndexOf('.'); if (nameEndIndex <= nameStartIndex) { - Logging.LogNullError(nameof(nameEndIndex)); + Bot.ArchiLogger.LogNullError(nameof(nameEndIndex)); return; } @@ -495,7 +495,7 @@ namespace ArchiSteamFarm { private async Task CheckPage(byte page) { if (page == 0) { - Logging.LogNullError(nameof(page), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(page)); return; } @@ -517,7 +517,7 @@ namespace ArchiSteamFarm { private async Task ShouldFarm(Game game) { if (game == null) { - Logging.LogNullError(nameof(game), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(game)); return false; } @@ -528,13 +528,13 @@ namespace ArchiSteamFarm { HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//span[@class='progress_info_bold']"); if (htmlNode == null) { - Logging.LogNullError(nameof(htmlNode), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(htmlNode)); return null; } string progress = htmlNode.InnerText; if (string.IsNullOrEmpty(progress)) { - Logging.LogNullError(nameof(progress), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(progress)); return null; } @@ -543,26 +543,26 @@ namespace ArchiSteamFarm { Match match = Regex.Match(progress, @"\d+"); if (match.Success) { if (!ushort.TryParse(match.Value, out cardsRemaining)) { - Logging.LogNullError(nameof(cardsRemaining), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(cardsRemaining)); return null; } } game.CardsRemaining = cardsRemaining; - Logging.LogGenericInfo("Status for " + game.AppID + " (" + game.GameName + "): " + cardsRemaining + " cards remaining", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Status for " + game.AppID + " (" + game.GameName + "): " + cardsRemaining + " cards remaining"); return cardsRemaining > 0; } private bool FarmMultiple(IEnumerable games) { if (games == null) { - Logging.LogNullError(nameof(games)); + Bot.ArchiLogger.LogNullError(nameof(games)); return false; } CurrentGamesFarming.ReplaceWith(games); - Logging.LogGenericInfo("Now farming: " + string.Join(", ", CurrentGamesFarming.Select(game => game.AppID)), Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Now farming: " + string.Join(", ", CurrentGamesFarming.Select(game => game.AppID))); bool result = FarmHours(CurrentGamesFarming); CurrentGamesFarming.ClearAndTrim(); @@ -571,13 +571,13 @@ namespace ArchiSteamFarm { private async Task FarmSolo(Game game) { if (game == null) { - Logging.LogNullError(nameof(game), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(game)); return true; } CurrentGamesFarming.Add(game); - Logging.LogGenericInfo("Now farming: " + game.AppID + " (" + game.GameName + ")", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Now farming: " + game.AppID + " (" + game.GameName + ")"); bool result = await Farm(game).ConfigureAwait(false); CurrentGamesFarming.ClearAndTrim(); @@ -589,13 +589,13 @@ namespace ArchiSteamFarm { GamesToFarm.Remove(game); TimeSpan timeSpan = TimeSpan.FromHours(game.HoursPlayed); - Logging.LogGenericInfo("Done farming: " + game.AppID + " (" + game.GameName + ") after " + timeSpan.ToString(@"hh\:mm") + " hours of playtime!", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Done farming: " + game.AppID + " (" + game.GameName + ") after " + timeSpan.ToString(@"hh\:mm") + " hours of playtime!"); return true; } private async Task Farm(Game game) { if (game == null) { - Logging.LogNullError(nameof(game), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(game)); return false; } @@ -606,7 +606,7 @@ namespace ArchiSteamFarm { bool? keepFarming = await ShouldFarm(game).ConfigureAwait(false); while (keepFarming.GetValueOrDefault(true) && (DateTime.Now < endFarmingDate)) { - Logging.LogGenericInfo("Still farming: " + game.AppID + " (" + game.GameName + ")", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Still farming: " + game.AppID + " (" + game.GameName + ")"); DateTime startFarmingPeriod = DateTime.Now; if (FarmResetEvent.Wait(60 * 1000 * Program.GlobalConfig.FarmingDelay)) { @@ -624,24 +624,24 @@ namespace ArchiSteamFarm { keepFarming = await ShouldFarm(game).ConfigureAwait(false); } - Logging.LogGenericInfo("Stopped farming: " + game.AppID + " (" + game.GameName + ")", Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Stopped farming: " + game.AppID + " (" + game.GameName + ")"); return success; } private bool FarmHours(ConcurrentHashSet games) { if ((games == null) || (games.Count == 0)) { - Logging.LogNullError(nameof(games), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(games)); return false; } float maxHour = games.Max(game => game.HoursPlayed); if (maxHour < 0) { - Logging.LogNullError(nameof(maxHour), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(maxHour)); return false; } if (maxHour >= 2) { - Logging.LogGenericError("Received request for past-2h games!", Bot.BotName); + Bot.ArchiLogger.LogGenericError("Received request for past-2h games!"); return true; } @@ -649,7 +649,7 @@ namespace ArchiSteamFarm { bool success = true; while (maxHour < 2) { - Logging.LogGenericInfo("Still farming: " + string.Join(", ", games.Select(game => game.AppID)), Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Still farming: " + string.Join(", ", games.Select(game => game.AppID))); DateTime startFarmingPeriod = DateTime.Now; if (FarmResetEvent.Wait(60 * 1000 * Program.GlobalConfig.FarmingDelay)) { @@ -670,7 +670,7 @@ namespace ArchiSteamFarm { maxHour += timePlayed; } - Logging.LogGenericInfo("Stopped farming: " + string.Join(", ", games.Select(game => game.AppID)), Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Stopped farming: " + string.Join(", ", games.Select(game => game.AppID))); return success; } diff --git a/ArchiSteamFarm/CryptoHelper.cs b/ArchiSteamFarm/CryptoHelper.cs index 806687f7e..ec32fa60b 100644 --- a/ArchiSteamFarm/CryptoHelper.cs +++ b/ArchiSteamFarm/CryptoHelper.cs @@ -38,7 +38,7 @@ namespace ArchiSteamFarm { internal static void SetEncryptionKey(string key) { if (string.IsNullOrEmpty(key)) { - Logging.LogNullError(nameof(key)); + ASF.ArchiLogger.LogNullError(nameof(key)); return; } @@ -47,7 +47,7 @@ namespace ArchiSteamFarm { internal static string Encrypt(ECryptoMethod cryptoMethod, string decrypted) { if (string.IsNullOrEmpty(decrypted)) { - Logging.LogNullError(nameof(decrypted)); + ASF.ArchiLogger.LogNullError(nameof(decrypted)); return null; } @@ -65,7 +65,7 @@ namespace ArchiSteamFarm { internal static string Decrypt(ECryptoMethod cryptoMethod, string encrypted) { if (string.IsNullOrEmpty(encrypted)) { - Logging.LogNullError(nameof(encrypted)); + ASF.ArchiLogger.LogNullError(nameof(encrypted)); return null; } @@ -83,7 +83,7 @@ namespace ArchiSteamFarm { private static string EncryptAES(string decrypted) { if (string.IsNullOrEmpty(decrypted)) { - Logging.LogNullError(nameof(decrypted)); + ASF.ArchiLogger.LogNullError(nameof(decrypted)); return null; } @@ -97,14 +97,14 @@ namespace ArchiSteamFarm { encryptedData = SteamKit2.CryptoHelper.SymmetricEncrypt(encryptedData, key); return Convert.ToBase64String(encryptedData); } catch (Exception e) { - Logging.LogGenericException(e); + ASF.ArchiLogger.LogGenericException(e); return null; } } private static string DecryptAES(string encrypted) { if (string.IsNullOrEmpty(encrypted)) { - Logging.LogNullError(nameof(encrypted)); + ASF.ArchiLogger.LogNullError(nameof(encrypted)); return null; } @@ -118,14 +118,14 @@ namespace ArchiSteamFarm { decryptedData = SteamKit2.CryptoHelper.SymmetricDecrypt(decryptedData, key); return Encoding.UTF8.GetString(decryptedData); } catch (Exception e) { - Logging.LogGenericException(e); + ASF.ArchiLogger.LogGenericException(e); return null; } } private static string EncryptProtectedDataForCurrentUser(string decrypted) { if (string.IsNullOrEmpty(decrypted)) { - Logging.LogNullError(nameof(decrypted)); + ASF.ArchiLogger.LogNullError(nameof(decrypted)); return null; } @@ -138,14 +138,14 @@ namespace ArchiSteamFarm { return Convert.ToBase64String(encryptedData); } catch (Exception e) { - Logging.LogGenericException(e); + ASF.ArchiLogger.LogGenericException(e); return null; } } private static string DecryptProtectedDataForCurrentUser(string encrypted) { if (string.IsNullOrEmpty(encrypted)) { - Logging.LogNullError(nameof(encrypted)); + ASF.ArchiLogger.LogNullError(nameof(encrypted)); return null; } @@ -158,7 +158,7 @@ namespace ArchiSteamFarm { return Encoding.UTF8.GetString(decryptedData); } catch (Exception e) { - Logging.LogGenericException(e); + ASF.ArchiLogger.LogGenericException(e); return null; } } diff --git a/ArchiSteamFarm/Debugging.cs b/ArchiSteamFarm/Debugging.cs index c0b32672e..af79f1d86 100644 --- a/ArchiSteamFarm/Debugging.cs +++ b/ArchiSteamFarm/Debugging.cs @@ -38,11 +38,11 @@ namespace ArchiSteamFarm { internal sealed class DebugListener : IDebugListener { public void WriteLine(string category, string msg) { if (string.IsNullOrEmpty(category) && string.IsNullOrEmpty(msg)) { - Logging.LogNullError(nameof(category) + " && " + nameof(msg)); + ASF.ArchiLogger.LogNullError(nameof(category) + " && " + nameof(msg)); return; } - Logging.LogGenericDebug(category + " | " + msg, nameof(DebugListener)); + ASF.ArchiLogger.LogGenericDebug(category + " | " + msg); } } } diff --git a/ArchiSteamFarm/Events.cs b/ArchiSteamFarm/Events.cs index 4c0ac9960..0c4ce5359 100644 --- a/ArchiSteamFarm/Events.cs +++ b/ArchiSteamFarm/Events.cs @@ -1,4 +1,28 @@ -using System.Linq; +/* + _ _ _ ____ _ _____ + / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ + / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ + / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| + + Copyright 2015-2016 Łukasz "JustArchi" Domeradzki + Contact: JustArchi@JustArchi.net + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +using System.Linq; using System.Threading.Tasks; using SteamKit2; @@ -12,7 +36,7 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericInfo("No bots are running, exiting"); + ASF.ArchiLogger.LogGenericInfo("No bots are running, exiting"); await Task.Delay(5000).ConfigureAwait(false); Program.Shutdown(); } diff --git a/ArchiSteamFarm/GlobalConfig.cs b/ArchiSteamFarm/GlobalConfig.cs index 449a04b7d..3c2ae80e1 100644 --- a/ArchiSteamFarm/GlobalConfig.cs +++ b/ArchiSteamFarm/GlobalConfig.cs @@ -113,7 +113,7 @@ namespace ArchiSteamFarm { internal static GlobalConfig Load(string filePath) { if (string.IsNullOrEmpty(filePath)) { - Logging.LogNullError(nameof(filePath)); + ASF.ArchiLogger.LogNullError(nameof(filePath)); return null; } @@ -126,12 +126,12 @@ namespace ArchiSteamFarm { try { globalConfig = JsonConvert.DeserializeObject(File.ReadAllText(filePath)); } catch (Exception e) { - Logging.LogGenericException(e); + ASF.ArchiLogger.LogGenericException(e); return null; } if (globalConfig == null) { - Logging.LogNullError(nameof(globalConfig)); + ASF.ArchiLogger.LogNullError(nameof(globalConfig)); return null; } @@ -142,24 +142,24 @@ namespace ArchiSteamFarm { case ProtocolType.Udp: break; default: - Logging.LogGenericWarning("Configured SteamProtocol is invalid: " + globalConfig.SteamProtocol); + ASF.ArchiLogger.LogGenericWarning("Configured SteamProtocol is invalid: " + globalConfig.SteamProtocol); return null; } // User might not know what he's doing // Ensure that he can't screw core ASF variables if (globalConfig.MaxFarmingTime == 0) { - Logging.LogGenericWarning("Configured MaxFarmingTime is invalid: " + globalConfig.MaxFarmingTime); + ASF.ArchiLogger.LogGenericWarning("Configured MaxFarmingTime is invalid: " + globalConfig.MaxFarmingTime); return null; } if (globalConfig.FarmingDelay == 0) { - Logging.LogGenericWarning("Configured FarmingDelay is invalid: " + globalConfig.FarmingDelay); + ASF.ArchiLogger.LogGenericWarning("Configured FarmingDelay is invalid: " + globalConfig.FarmingDelay); return null; } if (globalConfig.HttpTimeout == 0) { - Logging.LogGenericWarning("Configured HttpTimeout is invalid: " + globalConfig.HttpTimeout); + ASF.ArchiLogger.LogGenericWarning("Configured HttpTimeout is invalid: " + globalConfig.HttpTimeout); return null; } @@ -167,7 +167,7 @@ namespace ArchiSteamFarm { return globalConfig; } - Logging.LogGenericWarning("Configured WCFPort is invalid: " + globalConfig.WCFPort); + ASF.ArchiLogger.LogGenericWarning("Configured WCFPort is invalid: " + globalConfig.WCFPort); return null; } diff --git a/ArchiSteamFarm/GlobalDatabase.cs b/ArchiSteamFarm/GlobalDatabase.cs index 7bb64997a..77d2b4790 100644 --- a/ArchiSteamFarm/GlobalDatabase.cs +++ b/ArchiSteamFarm/GlobalDatabase.cs @@ -63,7 +63,7 @@ namespace ArchiSteamFarm { internal static GlobalDatabase Load(string filePath) { if (string.IsNullOrEmpty(filePath)) { - Logging.LogNullError(nameof(filePath)); + ASF.ArchiLogger.LogNullError(nameof(filePath)); return null; } @@ -76,12 +76,12 @@ namespace ArchiSteamFarm { try { globalDatabase = JsonConvert.DeserializeObject(File.ReadAllText(filePath), CustomSerializerSettings); } catch (Exception e) { - Logging.LogGenericException(e); + ASF.ArchiLogger.LogGenericException(e); return null; } if (globalDatabase == null) { - Logging.LogNullError(nameof(globalDatabase)); + ASF.ArchiLogger.LogNullError(nameof(globalDatabase)); return null; } @@ -114,7 +114,7 @@ namespace ArchiSteamFarm { private void Save() { string json = JsonConvert.SerializeObject(this, CustomSerializerSettings); if (string.IsNullOrEmpty(json)) { - Logging.LogNullError(nameof(json)); + ASF.ArchiLogger.LogNullError(nameof(json)); return; } @@ -124,7 +124,7 @@ namespace ArchiSteamFarm { File.WriteAllText(FilePath, json); break; } catch (Exception e) { - Logging.LogGenericException(e); + ASF.ArchiLogger.LogGenericException(e); } Thread.Sleep(1000); diff --git a/ArchiSteamFarm/InMemoryServerListProvider.cs b/ArchiSteamFarm/InMemoryServerListProvider.cs index a2e947eb1..6f9a101bd 100644 --- a/ArchiSteamFarm/InMemoryServerListProvider.cs +++ b/ArchiSteamFarm/InMemoryServerListProvider.cs @@ -40,7 +40,7 @@ namespace ArchiSteamFarm { public Task UpdateServerListAsync(IEnumerable endPoints) { if (endPoints == null) { - Logging.LogNullError(nameof(endPoints)); + ASF.ArchiLogger.LogNullError(nameof(endPoints)); return Task.Delay(0); } diff --git a/ArchiSteamFarm/JSON/Steam.cs b/ArchiSteamFarm/JSON/Steam.cs index 607c06093..45eb63ccb 100644 --- a/ArchiSteamFarm/JSON/Steam.cs +++ b/ArchiSteamFarm/JSON/Steam.cs @@ -62,13 +62,13 @@ namespace ArchiSteamFarm.JSON { set { if (string.IsNullOrEmpty(value)) { - Logging.LogNullError(nameof(value)); + ASF.ArchiLogger.LogNullError(nameof(value)); return; } uint appID; if (!uint.TryParse(value, out appID) || (appID == 0)) { - Logging.LogNullError(nameof(appID)); + ASF.ArchiLogger.LogNullError(nameof(appID)); return; } @@ -87,13 +87,13 @@ namespace ArchiSteamFarm.JSON { set { if (string.IsNullOrEmpty(value)) { - Logging.LogNullError(nameof(value)); + ASF.ArchiLogger.LogNullError(nameof(value)); return; } ulong contextID; if (!ulong.TryParse(value, out contextID) || (contextID == 0)) { - Logging.LogNullError(nameof(contextID)); + ASF.ArchiLogger.LogNullError(nameof(contextID)); return; } @@ -111,13 +111,13 @@ namespace ArchiSteamFarm.JSON { set { if (string.IsNullOrEmpty(value)) { - Logging.LogNullError(nameof(value)); + ASF.ArchiLogger.LogNullError(nameof(value)); return; } ulong assetID; if (!ulong.TryParse(value, out assetID) || (assetID == 0)) { - Logging.LogNullError(nameof(assetID)); + ASF.ArchiLogger.LogNullError(nameof(assetID)); return; } @@ -143,7 +143,7 @@ namespace ArchiSteamFarm.JSON { set { if (string.IsNullOrEmpty(value)) { - Logging.LogNullError(nameof(value)); + ASF.ArchiLogger.LogNullError(nameof(value)); return; } @@ -167,13 +167,13 @@ namespace ArchiSteamFarm.JSON { set { if (string.IsNullOrEmpty(value)) { - Logging.LogNullError(nameof(value)); + ASF.ArchiLogger.LogNullError(nameof(value)); return; } uint amount; if (!uint.TryParse(value, out amount) || (amount == 0)) { - Logging.LogNullError(nameof(amount)); + ASF.ArchiLogger.LogNullError(nameof(amount)); return; } @@ -234,7 +234,7 @@ namespace ArchiSteamFarm.JSON { } if (OtherSteamID3 == 0) { - Logging.LogNullError(nameof(OtherSteamID3)); + ASF.ArchiLogger.LogNullError(nameof(OtherSteamID3)); return 0; } @@ -363,7 +363,7 @@ namespace ArchiSteamFarm.JSON { set { if (value == null) { - Logging.LogNullError(nameof(value)); + ASF.ArchiLogger.LogNullError(nameof(value)); return; } @@ -417,25 +417,25 @@ namespace ArchiSteamFarm.JSON { HtmlNode htmlNode = HtmlDocument.DocumentNode.SelectSingleNode("//div[@class='tradeoffer']"); if (htmlNode == null) { - Logging.LogNullError(nameof(htmlNode)); + ASF.ArchiLogger.LogNullError(nameof(htmlNode)); return 0; } string id = htmlNode.GetAttributeValue("id", null); if (string.IsNullOrEmpty(id)) { - Logging.LogNullError(nameof(id)); + ASF.ArchiLogger.LogNullError(nameof(id)); return 0; } int index = id.IndexOf('_'); if (index < 0) { - Logging.LogNullError(nameof(index)); + ASF.ArchiLogger.LogNullError(nameof(index)); return 0; } index++; if (id.Length <= index) { - Logging.LogNullError(nameof(id.Length)); + ASF.ArchiLogger.LogNullError(nameof(id.Length)); return 0; } @@ -444,7 +444,7 @@ namespace ArchiSteamFarm.JSON { return _TradeOfferID; } - Logging.LogNullError(nameof(_TradeOfferID)); + ASF.ArchiLogger.LogNullError(nameof(_TradeOfferID)); return 0; } } @@ -483,13 +483,13 @@ namespace ArchiSteamFarm.JSON { HtmlNode htmlNode = HtmlDocument.DocumentNode.SelectSingleNode("//a/@data-miniprofile"); if (htmlNode == null) { - Logging.LogNullError(nameof(htmlNode)); + ASF.ArchiLogger.LogNullError(nameof(htmlNode)); return 0; } string miniProfile = htmlNode.GetAttributeValue("data-miniprofile", null); if (string.IsNullOrEmpty(miniProfile)) { - Logging.LogNullError(nameof(miniProfile)); + ASF.ArchiLogger.LogNullError(nameof(miniProfile)); return 0; } @@ -497,7 +497,7 @@ namespace ArchiSteamFarm.JSON { return _OtherSteamID3; } - Logging.LogNullError(nameof(_OtherSteamID3)); + ASF.ArchiLogger.LogNullError(nameof(_OtherSteamID3)); return 0; } } diff --git a/ArchiSteamFarm/Logging.cs b/ArchiSteamFarm/Logging.cs index c36b5582a..835915cb1 100644 --- a/ArchiSteamFarm/Logging.cs +++ b/ArchiSteamFarm/Logging.cs @@ -22,23 +22,18 @@ */ -using System; -using System.Diagnostics.CodeAnalysis; -using System.IO; using System.Linq; -using System.Runtime.CompilerServices; using NLog; using NLog.Config; using NLog.Targets; namespace ArchiSteamFarm { internal static class Logging { - private const string LayoutMessage = @"${message}${onexception:inner= ${exception:format=toString,Data}}"; + private const string LayoutMessage = @"${logger}|${message}${onexception:inner= ${exception:format=toString,Data}}"; private const string GeneralLayout = @"${date:format=yyyy-MM-dd HH\:mm\:ss}|${processname}-${processid}|${level:uppercase=true}|" + LayoutMessage; private const string EventLogLayout = LayoutMessage; private static readonly ConcurrentHashSet ConsoleLoggingRules = new ConcurrentHashSet(); - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static bool IsWaitingForUserInput; @@ -112,88 +107,6 @@ namespace ArchiSteamFarm { LogManager.ReconfigExistingLoggers(); } - internal static void LogGenericError(string message, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) { - if (string.IsNullOrEmpty(message)) { - LogNullError(nameof(message), botName); - return; - } - - Logger.Error($"{botName}|{previousMethodName}() {message}"); - } - - internal static void LogGenericException(Exception exception, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) { - if (exception == null) { - LogNullError(nameof(exception), botName); - return; - } - - Logger.Error(exception, $"{botName}|{previousMethodName}()"); - } - - internal static void LogFatalException(Exception exception, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) { - if (exception == null) { - LogNullError(nameof(exception), botName); - return; - } - - Logger.Fatal(exception, $"{botName}|{previousMethodName}()"); - - // If LogManager has been initialized already, don't do anything else - if (LogManager.Configuration != null) { - return; - } - - // Otherwise, if we run into fatal exception before logging module is even initialized, write exception to classic log file - File.WriteAllText(SharedInfo.LogFile, DateTime.Now + " ASF V" + SharedInfo.Version + " has run into fatal exception before core logging module was even able to initialize!" + Environment.NewLine); - - while (true) { - File.AppendAllText(SharedInfo.LogFile, "[!] EXCEPTION: " + previousMethodName + "() " + exception.Message + Environment.NewLine + "StackTrace:" + Environment.NewLine + exception.StackTrace); - if (exception.InnerException != null) { - exception = exception.InnerException; - continue; - } - - break; - } - } - - internal static void LogGenericWarning(string message, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) { - if (string.IsNullOrEmpty(message)) { - LogNullError(nameof(message), botName); - return; - } - - Logger.Warn($"{botName}|{previousMethodName}() {message}"); - } - - internal static void LogGenericInfo(string message, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) { - if (string.IsNullOrEmpty(message)) { - LogNullError(nameof(message), botName); - return; - } - - Logger.Info($"{botName}|{previousMethodName}() {message}"); - } - - [SuppressMessage("ReSharper", "ExplicitCallerInfoArgument")] - internal static void LogNullError(string nullObjectName, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) { - if (string.IsNullOrEmpty(nullObjectName)) { - return; - } - - LogGenericError(nullObjectName + " is null!", botName, previousMethodName); - } - - [SuppressMessage("ReSharper", "UnusedMember.Global")] - internal static void LogGenericDebug(string message, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) { - if (string.IsNullOrEmpty(message)) { - LogNullError(nameof(message), botName); - return; - } - - Logger.Debug($"{botName}|{previousMethodName}() {message}"); - } - private static void InitConsoleLoggers() { ConsoleLoggingRules.Clear(); foreach (LoggingRule loggingRule in LogManager.Configuration.LoggingRules.Where(loggingRule => loggingRule.Targets.Any(target => target is ColoredConsoleTarget || target is ConsoleTarget))) { @@ -203,7 +116,7 @@ namespace ArchiSteamFarm { private static void OnConfigurationChanged(object sender, LoggingConfigurationChangedEventArgs e) { if ((sender == null) || (e == null)) { - LogNullError(nameof(sender) + " || " + nameof(e)); + ASF.ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e)); return; } diff --git a/ArchiSteamFarm/MobileAuthenticator.cs b/ArchiSteamFarm/MobileAuthenticator.cs index 474c474fc..5646d7007 100644 --- a/ArchiSteamFarm/MobileAuthenticator.cs +++ b/ArchiSteamFarm/MobileAuthenticator.cs @@ -95,7 +95,7 @@ namespace ArchiSteamFarm { internal void CorrectDeviceID(string deviceID) { if (string.IsNullOrEmpty(deviceID)) { - Logging.LogNullError(nameof(deviceID), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(deviceID)); return; } @@ -104,12 +104,12 @@ namespace ArchiSteamFarm { internal async Task HandleConfirmations(HashSet confirmations, bool accept) { if ((confirmations == null) || (confirmations.Count == 0)) { - Logging.LogNullError(nameof(confirmations), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(confirmations)); return false; } if (!HasCorrectDeviceID) { - Logging.LogGenericWarning("Can't execute properly due to invalid DeviceID!", Bot.BotName); + Bot.ArchiLogger.LogGenericWarning("Can't execute properly due to invalid DeviceID!"); return false; } @@ -118,13 +118,13 @@ namespace ArchiSteamFarm { try { uint time = await GetSteamTime().ConfigureAwait(false); if (time == 0) { - Logging.LogNullError(nameof(time), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(time)); return false; } string confirmationHash = GenerateConfirmationKey(time, "conf"); if (string.IsNullOrEmpty(confirmationHash)) { - Logging.LogNullError(nameof(confirmationHash), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(confirmationHash)); return false; } @@ -156,24 +156,24 @@ namespace ArchiSteamFarm { internal async Task GetConfirmationDetails(Confirmation confirmation) { if (confirmation == null) { - Logging.LogNullError(nameof(confirmation), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(confirmation)); return null; } if (!HasCorrectDeviceID) { - Logging.LogGenericWarning("Can't execute properly due to invalid DeviceID!", Bot.BotName); + Bot.ArchiLogger.LogGenericWarning("Can't execute properly due to invalid DeviceID!"); return null; } uint time = await GetSteamTime().ConfigureAwait(false); if (time == 0) { - Logging.LogNullError(nameof(time), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(time)); return null; } string confirmationHash = GenerateConfirmationKey(time, "conf"); if (string.IsNullOrEmpty(confirmationHash)) { - Logging.LogNullError(nameof(confirmationHash), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(confirmationHash)); return null; } @@ -191,25 +191,25 @@ namespace ArchiSteamFarm { return GenerateTokenForTime(time); } - Logging.LogNullError(nameof(time), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(time)); return null; } internal async Task> GetConfirmations() { if (!HasCorrectDeviceID) { - Logging.LogGenericWarning("Can't execute properly due to invalid DeviceID!", Bot.BotName); + Bot.ArchiLogger.LogGenericWarning("Can't execute properly due to invalid DeviceID!"); return null; } uint time = await GetSteamTime().ConfigureAwait(false); if (time == 0) { - Logging.LogNullError(nameof(time), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(time)); return null; } string confirmationHash = GenerateConfirmationKey(time, "conf"); if (string.IsNullOrEmpty(confirmationHash)) { - Logging.LogNullError(nameof(confirmationHash), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(confirmationHash)); return null; } @@ -225,31 +225,31 @@ namespace ArchiSteamFarm { foreach (HtmlNode confirmationNode in confirmationNodes) { string idString = confirmationNode.GetAttributeValue("data-confid", null); if (string.IsNullOrEmpty(idString)) { - Logging.LogNullError(nameof(idString), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(idString)); return null; } uint id; if (!uint.TryParse(idString, out id) || (id == 0)) { - Logging.LogNullError(nameof(id), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(id)); return null; } string keyString = confirmationNode.GetAttributeValue("data-key", null); if (string.IsNullOrEmpty(keyString)) { - Logging.LogNullError(nameof(keyString), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(keyString)); return null; } ulong key; if (!ulong.TryParse(keyString, out key) || (key == 0)) { - Logging.LogNullError(nameof(key), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(key)); return null; } HtmlNode descriptionNode = confirmationNode.SelectSingleNode(".//div[@class='mobileconf_list_entry_description']/div"); if (descriptionNode == null) { - Logging.LogNullError(nameof(descriptionNode), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(descriptionNode)); return null; } @@ -261,7 +261,7 @@ namespace ArchiSteamFarm { } else if (description.StartsWith("Trade with ", StringComparison.Ordinal)) { type = Steam.ConfirmationDetails.EType.Trade; } else { - Logging.LogGenericWarning("Received unknown confirmation type, please report this: " + description, Bot.BotName); + Bot.ArchiLogger.LogGenericWarning("Received unknown confirmation type, please report this: " + description); type = Steam.ConfirmationDetails.EType.Other; } @@ -294,7 +294,7 @@ namespace ArchiSteamFarm { private string GenerateTokenForTime(uint time) { if (time == 0) { - Logging.LogNullError(nameof(time), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(time)); return null; } @@ -337,7 +337,7 @@ namespace ArchiSteamFarm { private string GenerateConfirmationKey(uint time, string tag = null) { if (time == 0) { - Logging.LogNullError(nameof(time), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(time)); return null; } diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index fe6e65078..77de4d9c6 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -42,7 +42,7 @@ namespace ArchiSteamFarm { private static readonly object ConsoleLock = new object(); private static readonly ManualResetEventSlim ShutdownResetEvent = new ManualResetEventSlim(false); - private static readonly WCF WCF = new WCF(); + private static readonly WCF WCF = new WCF(ASF.ArchiLogger); internal static bool IsRunningAsService { get; private set; } internal static EMode Mode { get; private set; } = EMode.Normal; @@ -67,7 +67,7 @@ namespace ArchiSteamFarm { try { Process.Start(Assembly.GetEntryAssembly().Location, string.Join(" ", Environment.GetCommandLineArgs().Skip(1))); } catch (Exception e) { - Logging.LogGenericException(e); + ASF.ArchiLogger.LogGenericException(e); } ShutdownResetEvent.Set(); @@ -80,7 +80,7 @@ namespace ArchiSteamFarm { } if (GlobalConfig.Headless || !Runtime.IsUserInteractive) { - Logging.LogGenericWarning("Received a request for user input, but process is running in headless mode!"); + ASF.ArchiLogger.LogGenericWarning("Received a request for user input, but process is running in headless mode!"); return null; } @@ -164,7 +164,7 @@ namespace ArchiSteamFarm { GlobalConfig = GlobalConfig.Load(globalConfigFile); if (GlobalConfig == null) { - Logging.LogGenericError("Global config could not be loaded, please make sure that " + globalConfigFile + " exists and is valid! Did you forget to read wiki?"); + ASF.ArchiLogger.LogGenericError("Global config could not be loaded, please make sure that " + globalConfigFile + " exists and is valid! Did you forget to read wiki?"); Thread.Sleep(5000); Exit(1); } @@ -173,7 +173,7 @@ namespace ArchiSteamFarm { GlobalDatabase = GlobalDatabase.Load(globalDatabaseFile); if (GlobalDatabase == null) { - Logging.LogGenericError("Global database could not be loaded, if issue persists, please remove " + globalDatabaseFile + " in order to recreate database!"); + ASF.ArchiLogger.LogGenericError("Global database could not be loaded, if issue persists, please remove " + globalDatabaseFile + " in order to recreate database!"); Thread.Sleep(5000); Exit(1); } @@ -182,12 +182,12 @@ namespace ArchiSteamFarm { WebBrowser.Init(); WCF.Init(); - WebBrowser = new WebBrowser(SharedInfo.ASF); + WebBrowser = new WebBrowser(ASF.ArchiLogger); } private static void ParsePreInitArgs(IEnumerable args) { if (args == null) { - Logging.LogNullError(nameof(args)); + ASF.ArchiLogger.LogNullError(nameof(args)); return; } @@ -215,7 +215,7 @@ namespace ArchiSteamFarm { private static void ParsePostInitArgs(IEnumerable args) { if (args == null) { - Logging.LogNullError(nameof(args)); + ASF.ArchiLogger.LogNullError(nameof(args)); return; } @@ -240,12 +240,12 @@ namespace ArchiSteamFarm { } if (Mode != EMode.Client) { - Logging.LogGenericWarning("Ignoring command because --client wasn't specified: " + arg); + ASF.ArchiLogger.LogGenericWarning("Ignoring command because --client wasn't specified: " + arg); break; } - Logging.LogGenericInfo("Command sent: " + arg); - Logging.LogGenericInfo("Response received: " + WCF.SendCommand(arg)); + ASF.ArchiLogger.LogGenericInfo("Command sent: " + arg); + ASF.ArchiLogger.LogGenericInfo("Response received: " + WCF.SendCommand(arg)); break; } } @@ -253,20 +253,20 @@ namespace ArchiSteamFarm { private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args) { if (args?.ExceptionObject == null) { - Logging.LogNullError(nameof(args) + " || " + nameof(args.ExceptionObject)); + ASF.ArchiLogger.LogNullError(nameof(args) + " || " + nameof(args.ExceptionObject)); return; } - Logging.LogFatalException((Exception) args.ExceptionObject); + ASF.ArchiLogger.LogFatalException((Exception) args.ExceptionObject); } private static void UnobservedTaskExceptionHandler(object sender, UnobservedTaskExceptionEventArgs args) { if (args?.Exception == null) { - Logging.LogNullError(nameof(args) + " || " + nameof(args.Exception)); + ASF.ArchiLogger.LogNullError(nameof(args) + " || " + nameof(args.Exception)); return; } - Logging.LogFatalException(args.Exception); + ASF.ArchiLogger.LogFatalException(args.Exception); } private static void Init(string[] args) { @@ -301,10 +301,10 @@ namespace ArchiSteamFarm { } Logging.InitLoggers(); - Logging.LogGenericInfo("ASF V" + SharedInfo.Version); + ASF.ArchiLogger.LogGenericInfo("ASF V" + SharedInfo.Version); if (!Runtime.IsRuntimeSupported) { - Logging.LogGenericError("ASF detected unsupported runtime version, program might NOT run correctly in current environment. You're running it at your own risk!"); + ASF.ArchiLogger.LogGenericError("ASF detected unsupported runtime version, program might NOT run correctly in current environment. You're running it at your own risk!"); Thread.Sleep(10000); } @@ -335,7 +335,7 @@ namespace ArchiSteamFarm { // From now on it's server mode if (!Directory.Exists(SharedInfo.ConfigDirectory)) { - Logging.LogGenericError("Config directory doesn't exist!"); + ASF.ArchiLogger.LogGenericError("Config directory doesn't exist!"); Thread.Sleep(5000); Exit(1); } @@ -357,7 +357,7 @@ namespace ArchiSteamFarm { } if (Bot.Bots.Count == 0) { - Logging.LogGenericWarning("No bots are defined, did you forget to configure your ASF?"); + ASF.ArchiLogger.LogGenericWarning("No bots are defined, did you forget to configure your ASF?"); } ASF.InitFileWatcher(); diff --git a/ArchiSteamFarm/Runtime.cs b/ArchiSteamFarm/Runtime.cs index 545902a5b..283e66197 100644 --- a/ArchiSteamFarm/Runtime.cs +++ b/ArchiSteamFarm/Runtime.cs @@ -65,38 +65,38 @@ namespace ArchiSteamFarm { if (IsRunningOnMono) { Version monoVersion = GetMonoVersion(); if (monoVersion == null) { - Logging.LogNullError(nameof(monoVersion)); + ASF.ArchiLogger.LogNullError(nameof(monoVersion)); return false; } Version minMonoVersion = new Version(4, 6); if (monoVersion >= minMonoVersion) { - Logging.LogGenericInfo("Your Mono version is OK. Required: " + minMonoVersion + " | Found: " + monoVersion); + ASF.ArchiLogger.LogGenericInfo("Your Mono version is OK. Required: " + minMonoVersion + " | Found: " + monoVersion); _IsRuntimeSupported = true; return true; } - Logging.LogGenericWarning("Your Mono version is too old. Required: " + minMonoVersion + " | Found: " + monoVersion); + ASF.ArchiLogger.LogGenericWarning("Your Mono version is too old. Required: " + minMonoVersion + " | Found: " + monoVersion); _IsRuntimeSupported = false; return false; } Version netVersion = GetNetVersion(); if (netVersion == null) { - Logging.LogNullError(nameof(netVersion)); + ASF.ArchiLogger.LogNullError(nameof(netVersion)); return false; } Version minNetVersion = new Version(4, 6, 1); if (netVersion >= minNetVersion) { - Logging.LogGenericInfo("Your .NET version is OK. Required: " + minNetVersion + " | Found: " + netVersion); + ASF.ArchiLogger.LogGenericInfo("Your .NET version is OK. Required: " + minNetVersion + " | Found: " + netVersion); _IsRuntimeSupported = true; return true; } - Logging.LogGenericWarning("Your .NET version is too old. Required: " + minNetVersion + " | Found: " + netVersion); + ASF.ArchiLogger.LogGenericWarning("Your .NET version is too old. Required: " + minNetVersion + " | Found: " + netVersion); _IsRuntimeSupported = false; return false; } @@ -106,18 +106,18 @@ namespace ArchiSteamFarm { uint release; using (RegistryKey registryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full\\")) { if (registryKey == null) { - Logging.LogNullError(nameof(registryKey)); + ASF.ArchiLogger.LogNullError(nameof(registryKey)); return null; } object releaseObj = registryKey.GetValue("Release"); if (releaseObj == null) { - Logging.LogNullError(nameof(releaseObj)); + ASF.ArchiLogger.LogNullError(nameof(releaseObj)); return null; } if (!uint.TryParse(releaseObj.ToString(), out release) || (release == 0)) { - Logging.LogNullError(nameof(release)); + ASF.ArchiLogger.LogNullError(nameof(release)); return null; } } @@ -147,25 +147,25 @@ namespace ArchiSteamFarm { private static Version GetMonoVersion() { if (MonoRuntime == null) { - Logging.LogNullError(nameof(MonoRuntime)); + ASF.ArchiLogger.LogNullError(nameof(MonoRuntime)); return null; } MethodInfo displayName = MonoRuntime.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); if (displayName == null) { - Logging.LogNullError(nameof(displayName)); + ASF.ArchiLogger.LogNullError(nameof(displayName)); return null; } string versionString = (string) displayName.Invoke(null, null); if (string.IsNullOrEmpty(versionString)) { - Logging.LogNullError(nameof(versionString)); + ASF.ArchiLogger.LogNullError(nameof(versionString)); return null; } int index = versionString.IndexOf(' '); if (index <= 0) { - Logging.LogNullError(nameof(index)); + ASF.ArchiLogger.LogNullError(nameof(index)); return null; } @@ -176,7 +176,7 @@ namespace ArchiSteamFarm { return version; } - Logging.LogNullError(nameof(version)); + ASF.ArchiLogger.LogNullError(nameof(version)); return null; } } diff --git a/ArchiSteamFarm/Trading.cs b/ArchiSteamFarm/Trading.cs index ac896a8f6..4d53de082 100644 --- a/ArchiSteamFarm/Trading.cs +++ b/ArchiSteamFarm/Trading.cs @@ -140,32 +140,32 @@ namespace ArchiSteamFarm { private async Task ParseTrade(Steam.TradeOffer tradeOffer) { if (tradeOffer == null) { - Logging.LogNullError(nameof(tradeOffer), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(tradeOffer)); return null; } if (tradeOffer.State != Steam.TradeOffer.ETradeOfferState.Active) { - Logging.LogGenericError("Ignoring trade in non-active state!", Bot.BotName); + Bot.ArchiLogger.LogGenericError("Ignoring trade in non-active state!"); return null; } ParseTradeResult result = await ShouldAcceptTrade(tradeOffer).ConfigureAwait(false); if (result == null) { - Logging.LogNullError(nameof(result), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(result)); return null; } switch (result.Result) { case ParseTradeResult.EResult.AcceptedWithItemLose: case ParseTradeResult.EResult.AcceptedWithoutItemLose: - Logging.LogGenericInfo("Accepting trade: " + tradeOffer.TradeOfferID, Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Accepting trade: " + tradeOffer.TradeOfferID); await Bot.ArchiWebHandler.AcceptTradeOffer(tradeOffer.TradeOfferID).ConfigureAwait(false); break; case ParseTradeResult.EResult.RejectedPermanently: case ParseTradeResult.EResult.RejectedTemporarily: if (result.Result == ParseTradeResult.EResult.RejectedPermanently) { if (Bot.BotConfig.IsBotAccount) { - Logging.LogGenericInfo("Rejecting trade: " + tradeOffer.TradeOfferID, Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Rejecting trade: " + tradeOffer.TradeOfferID); Bot.ArchiWebHandler.DeclineTradeOffer(tradeOffer.TradeOfferID); break; } @@ -173,7 +173,7 @@ namespace ArchiSteamFarm { IgnoredTrades.Add(tradeOffer.TradeOfferID); } - Logging.LogGenericInfo("Ignoring trade: " + tradeOffer.TradeOfferID, Bot.BotName); + Bot.ArchiLogger.LogGenericInfo("Ignoring trade: " + tradeOffer.TradeOfferID); break; } @@ -182,7 +182,7 @@ namespace ArchiSteamFarm { private async Task ShouldAcceptTrade(Steam.TradeOffer tradeOffer) { if (tradeOffer == null) { - Logging.LogNullError(nameof(tradeOffer), Bot.BotName); + Bot.ArchiLogger.LogNullError(nameof(tradeOffer)); return null; } diff --git a/ArchiSteamFarm/Utilities.cs b/ArchiSteamFarm/Utilities.cs index 7a1657026..31d09fa78 100644 --- a/ArchiSteamFarm/Utilities.cs +++ b/ArchiSteamFarm/Utilities.cs @@ -36,7 +36,7 @@ namespace ArchiSteamFarm { internal static string GetCookieValue(this CookieContainer cookieContainer, string url, string name) { if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(name)) { - Logging.LogNullError(nameof(url) + " || " + nameof(name)); + ASF.ArchiLogger.LogNullError(nameof(url) + " || " + nameof(name)); return null; } @@ -45,7 +45,7 @@ namespace ArchiSteamFarm { try { uri = new Uri(url); } catch (UriFormatException e) { - Logging.LogGenericException(e); + ASF.ArchiLogger.LogGenericException(e); return null; } diff --git a/ArchiSteamFarm/WCF.cs b/ArchiSteamFarm/WCF.cs index fb46fe380..011c0c69b 100644 --- a/ArchiSteamFarm/WCF.cs +++ b/ArchiSteamFarm/WCF.cs @@ -39,14 +39,23 @@ namespace ArchiSteamFarm { } internal sealed class WCF : IWCF, IDisposable { - private static string URL = "http://localhost:1242/ASF"; + private readonly ArchiLogger ArchiLogger; + private ServiceHost ServiceHost; private Client Client; internal bool IsServerRunning => ServiceHost != null; + internal WCF(ArchiLogger archiLogger) { + if (archiLogger == null) { + throw new ArgumentNullException(nameof(archiLogger)); + } + + ArchiLogger = archiLogger; + } + internal static void Init() { if (string.IsNullOrEmpty(Program.GlobalConfig.WCFHostname)) { Program.GlobalConfig.WCFHostname = Program.GetUserInput(SharedInfo.EUserInputType.WCFHostname); @@ -60,7 +69,7 @@ namespace ArchiSteamFarm { public string HandleCommand(string input) { if (string.IsNullOrEmpty(input)) { - Logging.LogNullError(nameof(input)); + ArchiLogger.LogNullError(nameof(input)); return null; } @@ -76,7 +85,7 @@ namespace ArchiSteamFarm { string command = "!" + input; string output = bot.Response(Program.GlobalConfig.SteamOwnerID, command).Result; // TODO: This should be asynchronous - Logging.LogGenericInfo("Answered to command: " + input + " with: " + output); + ArchiLogger.LogGenericInfo("Answered to command: " + input + " with: " + output); return output; } @@ -92,7 +101,7 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericInfo("Starting WCF server..."); + ArchiLogger.LogGenericInfo("Starting WCF server..."); try { ServiceHost = new ServiceHost(typeof(WCF), new Uri(URL)); @@ -106,11 +115,11 @@ namespace ArchiSteamFarm { ServiceHost.Open(); } catch (Exception e) { - Logging.LogGenericException(e); + ArchiLogger.LogGenericException(e); return; } - Logging.LogGenericInfo("WCF server ready!"); + ArchiLogger.LogGenericInfo("WCF server ready!"); } internal void StopServer() { @@ -122,7 +131,7 @@ namespace ArchiSteamFarm { try { ServiceHost.Close(); } catch (Exception e) { - Logging.LogGenericException(e); + ArchiLogger.LogGenericException(e); } } @@ -131,12 +140,12 @@ namespace ArchiSteamFarm { internal string SendCommand(string input) { if (string.IsNullOrEmpty(input)) { - Logging.LogNullError(nameof(input)); + ArchiLogger.LogNullError(nameof(input)); return null; } if (Client == null) { - Client = new Client(new BasicHttpBinding(), new EndpointAddress(URL)); + Client = new Client(new BasicHttpBinding(), new EndpointAddress(URL), ArchiLogger); } return Client.HandleCommand(input); @@ -156,18 +165,26 @@ namespace ArchiSteamFarm { } internal sealed class Client : ClientBase { - internal Client(Binding binding, EndpointAddress address) : base(binding, address) { } + private readonly ArchiLogger ArchiLogger; + + internal Client(Binding binding, EndpointAddress address, ArchiLogger archiLogger) : base(binding, address) { + if (archiLogger == null) { + throw new ArgumentNullException(nameof(archiLogger)); + } + + ArchiLogger = archiLogger; + } internal string HandleCommand(string input) { if (string.IsNullOrEmpty(input)) { - Logging.LogNullError(nameof(input)); + ArchiLogger.LogNullError(nameof(input)); return null; } try { return Channel.HandleCommand(input); } catch (Exception e) { - Logging.LogGenericException(e); + ArchiLogger.LogGenericException(e); return null; } } diff --git a/ArchiSteamFarm/WebBrowser.cs b/ArchiSteamFarm/WebBrowser.cs index 2c02d91da..cedc00cbb 100644 --- a/ArchiSteamFarm/WebBrowser.cs +++ b/ArchiSteamFarm/WebBrowser.cs @@ -41,8 +41,8 @@ namespace ArchiSteamFarm { internal readonly CookieContainer CookieContainer = new CookieContainer(); + private readonly ArchiLogger ArchiLogger; private readonly HttpClient HttpClient; - private readonly string Identifier; internal static void Init() { // Set max connection limit from default of 2 to desired value @@ -70,12 +70,12 @@ namespace ArchiSteamFarm { private static void InitNonMonoBehaviour() => ServicePointManager.ReusePort = true; #endif - internal WebBrowser(string identifier) { - if (string.IsNullOrEmpty(identifier)) { - throw new ArgumentNullException(nameof(identifier)); + internal WebBrowser(ArchiLogger archiLogger) { + if (archiLogger == null) { + throw new ArgumentNullException(nameof(archiLogger)); } - Identifier = identifier; + ArchiLogger = archiLogger; HttpClientHandler httpClientHandler = new HttpClientHandler { AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, @@ -92,7 +92,7 @@ namespace ArchiSteamFarm { internal async Task UrlHeadRetry(string request, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return false; } @@ -105,13 +105,13 @@ namespace ArchiSteamFarm { return true; } - Logging.LogGenericWarning("Request failed even after " + MaxRetries + " tries", Identifier); + ArchiLogger.LogGenericWarning("Request failed even after " + MaxRetries + " tries"); return false; } internal async Task UrlHeadToUriRetry(string request, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } @@ -124,13 +124,13 @@ namespace ArchiSteamFarm { return result; } - Logging.LogGenericWarning("Request failed even after " + MaxRetries + " tries", Identifier); + ArchiLogger.LogGenericWarning("Request failed even after " + MaxRetries + " tries"); return null; } internal async Task UrlGetToBytesRetry(string request, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } @@ -143,13 +143,13 @@ namespace ArchiSteamFarm { return result; } - Logging.LogGenericWarning("Request failed even after " + MaxRetries + " tries", Identifier); + ArchiLogger.LogGenericWarning("Request failed even after " + MaxRetries + " tries"); return null; } internal async Task UrlGetToHtmlDocumentRetry(string request, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } @@ -162,13 +162,13 @@ namespace ArchiSteamFarm { return result; } - Logging.LogGenericWarning("Request failed even after " + MaxRetries + " tries", Identifier); + ArchiLogger.LogGenericWarning("Request failed even after " + MaxRetries + " tries"); return null; } internal async Task UrlGetToJObjectRetry(string request, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } @@ -181,13 +181,13 @@ namespace ArchiSteamFarm { return result; } - Logging.LogGenericWarning("Request failed even after " + MaxRetries + " tries", Identifier); + ArchiLogger.LogGenericWarning("Request failed even after " + MaxRetries + " tries"); return null; } internal async Task UrlGetToJsonResultRetry(string request, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return default(T); } @@ -199,14 +199,14 @@ namespace ArchiSteamFarm { try { return JsonConvert.DeserializeObject(json); } catch (JsonException e) { - Logging.LogGenericException(e, Identifier); + ArchiLogger.LogGenericException(e); return default(T); } } internal async Task UrlGetToXMLRetry(string request, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } @@ -219,13 +219,13 @@ namespace ArchiSteamFarm { return result; } - Logging.LogGenericWarning("Request failed even after " + MaxRetries + " tries", Identifier); + ArchiLogger.LogGenericWarning("Request failed even after " + MaxRetries + " tries"); return null; } internal async Task UrlPostRetry(string request, ICollection> data = null, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return false; } @@ -238,13 +238,13 @@ namespace ArchiSteamFarm { return true; } - Logging.LogGenericWarning("Request failed even after " + MaxRetries + " tries", Identifier); + ArchiLogger.LogGenericWarning("Request failed even after " + MaxRetries + " tries"); return false; } internal async Task UrlPostToJsonResultRetry(string request, ICollection> data = null, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return default(T); } @@ -256,14 +256,14 @@ namespace ArchiSteamFarm { try { return JsonConvert.DeserializeObject(json); } catch (JsonException e) { - Logging.LogGenericException(e, Identifier); + ArchiLogger.LogGenericException(e); return default(T); } } private async Task UrlGetToBytes(string request, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } @@ -278,7 +278,7 @@ namespace ArchiSteamFarm { private async Task UrlGetToContent(string request, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } @@ -293,7 +293,7 @@ namespace ArchiSteamFarm { private async Task UrlGetToContentRetry(string request, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } @@ -306,13 +306,13 @@ namespace ArchiSteamFarm { return result; } - Logging.LogGenericWarning("Request failed even after " + MaxRetries + " tries", Identifier); + ArchiLogger.LogGenericWarning("Request failed even after " + MaxRetries + " tries"); return null; } private async Task UrlGetToHtmlDocument(string request, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } @@ -328,7 +328,7 @@ namespace ArchiSteamFarm { private async Task UrlGetToJObject(string request, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } @@ -342,7 +342,7 @@ namespace ArchiSteamFarm { try { jObject = JObject.Parse(json); } catch (JsonException e) { - Logging.LogGenericException(e, Identifier); + ArchiLogger.LogGenericException(e); return null; } @@ -354,13 +354,13 @@ namespace ArchiSteamFarm { return await UrlRequest(request, HttpMethod.Get, null, referer).ConfigureAwait(false); } - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } private async Task UrlGetToXML(string request, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } @@ -374,7 +374,7 @@ namespace ArchiSteamFarm { try { xmlDocument.LoadXml(xml); } catch (XmlException e) { - Logging.LogGenericException(e, Identifier); + ArchiLogger.LogGenericException(e); return null; } @@ -383,7 +383,7 @@ namespace ArchiSteamFarm { private async Task UrlHead(string request, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return false; } @@ -397,13 +397,13 @@ namespace ArchiSteamFarm { return await UrlRequest(request, HttpMethod.Head, null, referer).ConfigureAwait(false); } - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } private async Task UrlHeadToUri(string request, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } @@ -414,7 +414,7 @@ namespace ArchiSteamFarm { private async Task UrlPost(string request, IEnumerable> data = null, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return false; } @@ -425,7 +425,7 @@ namespace ArchiSteamFarm { private async Task UrlPostToContent(string request, IEnumerable> data = null, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } @@ -440,7 +440,7 @@ namespace ArchiSteamFarm { private async Task UrlPostToContentRetry(string request, ICollection> data = null, string referer = null) { if (string.IsNullOrEmpty(request)) { - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } @@ -453,7 +453,7 @@ namespace ArchiSteamFarm { return result; } - Logging.LogGenericWarning("Request failed even after " + MaxRetries + " tries", Identifier); + ArchiLogger.LogGenericWarning("Request failed even after " + MaxRetries + " tries"); return null; } @@ -462,13 +462,13 @@ namespace ArchiSteamFarm { return await UrlRequest(request, HttpMethod.Post, data, referer).ConfigureAwait(false); } - Logging.LogNullError(nameof(request), Identifier); + ArchiLogger.LogNullError(nameof(request)); return null; } private async Task UrlRequest(string request, HttpMethod httpMethod, IEnumerable> data = null, string referer = null) { if (string.IsNullOrEmpty(request) || (httpMethod == null)) { - Logging.LogNullError(nameof(request) + " || " + nameof(httpMethod), Identifier); + ArchiLogger.LogNullError(nameof(request) + " || " + nameof(httpMethod)); return null; } @@ -482,7 +482,7 @@ namespace ArchiSteamFarm { try { requestMessage.Content = new FormUrlEncodedContent(data); } catch (UriFormatException e) { - Logging.LogGenericException(e, Identifier); + ArchiLogger.LogGenericException(e); return null; } } @@ -496,7 +496,7 @@ namespace ArchiSteamFarm { } catch (Exception e) { // This exception is really common, don't bother with it unless debug mode is enabled if (Debugging.IsDebugBuild || Program.GlobalConfig.Debug) { - Logging.LogGenericException(e, Identifier); + ArchiLogger.LogGenericException(e); } return null; @@ -512,9 +512,9 @@ namespace ArchiSteamFarm { } if (Debugging.IsDebugBuild || Program.GlobalConfig.Debug) { - Logging.LogGenericError("Request: " + request + " failed!", Identifier); - Logging.LogGenericError("Status code: " + responseMessage.StatusCode, Identifier); - Logging.LogGenericError("Content: " + Environment.NewLine + await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false), Identifier); + ArchiLogger.LogGenericError("Request: " + request + " failed!"); + ArchiLogger.LogGenericError("Status code: " + responseMessage.StatusCode); + ArchiLogger.LogGenericError("Content: " + Environment.NewLine + await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false)); } responseMessage.Dispose(); diff --git a/GUI/BotStatusForm.cs b/GUI/BotStatusForm.cs index 02686fc5e..a15e8c6b2 100644 --- a/GUI/BotStatusForm.cs +++ b/GUI/BotStatusForm.cs @@ -27,7 +27,7 @@ namespace GUI { internal void OnStateUpdated(SteamFriends.PersonaStateCallback callback) { if (callback == null) { - Logging.LogNullError(nameof(callback)); + Bot.ArchiLogger.LogNullError(nameof(callback)); return; } diff --git a/GUI/Events.cs b/GUI/Events.cs index 342bab6df..f2be04e33 100644 --- a/GUI/Events.cs +++ b/GUI/Events.cs @@ -1,4 +1,28 @@ -using GUI; +/* + _ _ _ ____ _ _____ + / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ + / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ + / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| + + Copyright 2015-2016 Łukasz "JustArchi" Domeradzki + Contact: JustArchi@JustArchi.net + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +using GUI; using SteamKit2; // ReSharper disable once CheckNamespace @@ -7,8 +31,13 @@ namespace ArchiSteamFarm { internal static void OnBotShutdown() { } internal static void OnStateUpdated(Bot bot, SteamFriends.PersonaStateCallback callback) { - if ((bot == null) || (callback == null)) { - Logging.LogNullError(nameof(bot) + " || " + nameof(callback)); + if (bot == null) { + ASF.ArchiLogger.LogNullError(nameof(bot)); + return; + } + + if (callback == null) { + bot.ArchiLogger.LogNullError(nameof(callback)); return; } diff --git a/GUI/GUI.csproj b/GUI/GUI.csproj index 9374c3a0c..221ad6323 100644 --- a/GUI/GUI.csproj +++ b/GUI/GUI.csproj @@ -82,6 +82,9 @@ ArchiHandler.cs + + ArchiLogger.cs + ArchiWebHandler.cs diff --git a/GUI/Logging.cs b/GUI/Logging.cs index 7a711e215..2090e5605 100644 --- a/GUI/Logging.cs +++ b/GUI/Logging.cs @@ -22,11 +22,7 @@ */ -using System; -using System.Diagnostics.CodeAnalysis; -using System.IO; using System.Linq; -using System.Runtime.CompilerServices; using NLog; using NLog.Config; using NLog.Targets; @@ -35,9 +31,7 @@ using NLog.Windows.Forms; // ReSharper disable once CheckNamespace namespace ArchiSteamFarm { internal static class Logging { - private const string GeneralLayout = @"${date:format=yyyy-MM-dd HH\:mm\:ss} | ${level:uppercase=true} | ${message}${onexception:inner= | ${exception:format=toString,Data}}"; - - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private const string GeneralLayout = @"${date:format=yyyy-MM-dd HH\:mm\:ss} | ${level:uppercase=true} | ${logger} | ${message}${onexception:inner= | ${exception:format=toString,Data}}"; private static bool IsUsingCustomConfiguration; @@ -98,88 +92,5 @@ namespace ArchiSteamFarm { LogManager.ReconfigExistingLoggers(); } - - internal static void LogGenericError(string message, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) { - if (string.IsNullOrEmpty(message)) { - LogNullError(nameof(message), botName); - return; - } - - Logger.Error($"{botName}|{previousMethodName}() {message}"); - } - - internal static void LogGenericException(Exception exception, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) { - if (exception == null) { - LogNullError(nameof(exception), botName); - return; - } - - Logger.Error(exception, $"{botName}|{previousMethodName}()"); - } - - [SuppressMessage("ReSharper", "LocalizableElement")] - internal static void LogFatalException(Exception exception, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) { - if (exception == null) { - LogNullError(nameof(exception), botName); - return; - } - - Logger.Fatal(exception, $"{botName}|{previousMethodName}()"); - - // If LogManager has been initialized already, don't do anything else - if (LogManager.Configuration != null) { - return; - } - - // Otherwise, if we run into fatal exception before logging module is even initialized, write exception to classic log file - File.WriteAllText(SharedInfo.LogFile, DateTime.Now + " ASF V" + SharedInfo.Version + " has run into fatal exception before core logging module was even able to initialize!" + Environment.NewLine); - - while (true) { - File.AppendAllText(SharedInfo.LogFile, "[!] EXCEPTION: " + previousMethodName + "() " + exception.Message + Environment.NewLine + "StackTrace:" + Environment.NewLine + exception.StackTrace); - if (exception.InnerException != null) { - exception = exception.InnerException; - continue; - } - - break; - } - } - - internal static void LogGenericWarning(string message, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) { - if (string.IsNullOrEmpty(message)) { - LogNullError(nameof(message), botName); - return; - } - - Logger.Warn($"{botName}|{previousMethodName}() {message}"); - } - - internal static void LogGenericInfo(string message, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) { - if (string.IsNullOrEmpty(message)) { - LogNullError(nameof(message), botName); - return; - } - - Logger.Info($"{botName}|{previousMethodName}() {message}"); - } - - [SuppressMessage("ReSharper", "ExplicitCallerInfoArgument")] - internal static void LogNullError(string nullObjectName, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) { - if (string.IsNullOrEmpty(nullObjectName)) { - return; - } - - LogGenericError(nullObjectName + " is null!", botName, previousMethodName); - } - - [SuppressMessage("ReSharper", "UnusedMember.Global")] - internal static void LogGenericDebug(string message, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) { - if (string.IsNullOrEmpty(message)) { - LogNullError(nameof(message), botName); - return; - } - - Logger.Debug($"{botName}|{previousMethodName}() {message}"); - } } } diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index 3abef99ba..56619f6eb 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -23,7 +23,7 @@ namespace GUI { internal static void UpdateBotAvatar(string botName, Image image) { if (string.IsNullOrEmpty(botName) || (image == null)) { - Logging.LogNullError(nameof(botName) + " || " + nameof(image)); + ASF.ArchiLogger.LogNullError(nameof(botName) + " || " + nameof(image)); return; } @@ -49,7 +49,7 @@ namespace GUI { private static Bitmap ResizeImage(Image image, int width, int height) { if ((image == null) || (width <= 0) || (height <= 0)) { - Logging.LogNullError(nameof(image) + " || " + nameof(width) + " || " + nameof(height)); + ASF.ArchiLogger.LogNullError(nameof(image) + " || " + nameof(width) + " || " + nameof(height)); return null; } @@ -92,10 +92,10 @@ namespace GUI { BotListView.LargeImageList = BotListView.SmallImageList = AvatarImageList; await Task.Run(async () => { - Logging.LogGenericInfo("ASF V" + SharedInfo.Version); + ASF.ArchiLogger.LogGenericInfo("ASF V" + SharedInfo.Version); if (!Directory.Exists(SharedInfo.ConfigDirectory)) { - Logging.LogGenericError("Config directory could not be found!"); + ASF.ArchiLogger.LogGenericError("Config directory could not be found!"); Environment.Exit(1); } diff --git a/GUI/Program.cs b/GUI/Program.cs index 87da00f79..819be2964 100644 --- a/GUI/Program.cs +++ b/GUI/Program.cs @@ -30,7 +30,7 @@ namespace ArchiSteamFarm { try { Process.Start(Assembly.GetEntryAssembly().Location, string.Join(" ", Environment.GetCommandLineArgs().Skip(1))); } catch (Exception e) { - Logging.LogGenericException(e); + ASF.ArchiLogger.LogGenericException(e); } Environment.Exit(0); @@ -44,20 +44,20 @@ namespace ArchiSteamFarm { private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args) { if (args?.ExceptionObject == null) { - Logging.LogNullError(nameof(args) + " || " + nameof(args.ExceptionObject)); + ASF.ArchiLogger.LogNullError(nameof(args) + " || " + nameof(args.ExceptionObject)); return; } - Logging.LogFatalException((Exception) args.ExceptionObject); + ASF.ArchiLogger.LogFatalException((Exception) args.ExceptionObject); } private static void UnobservedTaskExceptionHandler(object sender, UnobservedTaskExceptionEventArgs args) { if (args?.Exception == null) { - Logging.LogNullError(nameof(args) + " || " + nameof(args.Exception)); + ASF.ArchiLogger.LogNullError(nameof(args) + " || " + nameof(args.Exception)); return; } - Logging.LogFatalException(args.Exception); + ASF.ArchiLogger.LogFatalException(args.Exception); } private static void InitServices() { @@ -65,7 +65,7 @@ namespace ArchiSteamFarm { GlobalConfig = GlobalConfig.Load(globalConfigFile); if (GlobalConfig == null) { - Logging.LogGenericError("Global config could not be loaded, please make sure that " + globalConfigFile + " exists and is valid!"); + ASF.ArchiLogger.LogGenericError("Global config could not be loaded, please make sure that " + globalConfigFile + " exists and is valid!"); Exit(1); } @@ -73,14 +73,14 @@ namespace ArchiSteamFarm { GlobalDatabase = GlobalDatabase.Load(globalDatabaseFile); if (GlobalDatabase == null) { - Logging.LogGenericError("Global database could not be loaded, if issue persists, please remove " + globalDatabaseFile + " in order to recreate database!"); + ASF.ArchiLogger.LogGenericError("Global database could not be loaded, if issue persists, please remove " + globalDatabaseFile + " in order to recreate database!"); Exit(1); } ArchiWebHandler.Init(); WebBrowser.Init(); - WebBrowser = new WebBrowser(SharedInfo.ASF); + WebBrowser = new WebBrowser(ASF.ArchiLogger); } private static void Init() { @@ -90,7 +90,7 @@ namespace ArchiSteamFarm { Logging.InitCoreLoggers(); if (!Runtime.IsRuntimeSupported) { - Logging.LogGenericError("ASF detected unsupported runtime version, program might NOT run correctly in current environment. You're running it at your own risk!"); + ASF.ArchiLogger.LogGenericError("ASF detected unsupported runtime version, program might NOT run correctly in current environment. You're running it at your own risk!"); } string homeDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);