From 049b78eb0290496ef4e8fb40a3dfcbbbe3a836a7 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sun, 24 Jan 2016 18:08:27 +0100 Subject: [PATCH] Rewrite logging a bit --- ArchiSteamFarm/ArchiWebHandler.cs | 42 ++++++++++---------- ArchiSteamFarm/Bot.cs | 66 +++++++++++++++---------------- ArchiSteamFarm/CardsFarmer.cs | 52 ++++++++++++------------ ArchiSteamFarm/Logging.cs | 26 +++++------- ArchiSteamFarm/Program.cs | 30 +++++++------- ArchiSteamFarm/Trading.cs | 4 +- ArchiSteamFarm/WCF.cs | 16 ++++---- 7 files changed, 114 insertions(+), 122 deletions(-) diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 307e2c9cf..00c975144 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -60,7 +60,7 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericInfo(Bot.BotName, "Unlocking parental account..."); + Logging.LogGenericInfo("Unlocking parental account...", Bot.BotName); Dictionary data = new Dictionary() { { "pin", parentalPin } }; @@ -71,13 +71,13 @@ namespace ArchiSteamFarm { } if (response == null) { - Logging.LogGenericWTF(Bot.BotName, "Request failed even after " + WebBrowser.MaxRetries + " tries"); + Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); return; } IEnumerable setCookieValues; if (!response.Headers.TryGetValues("Set-Cookie", out setCookieValues)) { - Logging.LogNullError(Bot.BotName, "setCookieValues"); + Logging.LogNullError("setCookieValues", Bot.BotName); return; } @@ -86,12 +86,12 @@ namespace ArchiSteamFarm { string setCookie = setCookieValue.Substring(setCookieValue.IndexOf("steamparental=") + 14); setCookie = setCookie.Substring(0, setCookie.IndexOf(';')); Cookie.Add("steamparental", setCookie); - Logging.LogGenericInfo(Bot.BotName, "Success!"); + Logging.LogGenericInfo("Success!", Bot.BotName); return; } } - Logging.LogGenericWarning(Bot.BotName, "Failed to unlock parental account!"); + Logging.LogGenericWarning("Failed to unlock parental account!", Bot.BotName); } internal ArchiWebHandler(Bot bot, string apiKey) { @@ -130,7 +130,7 @@ namespace ArchiSteamFarm { // Send the magic KeyValue authResult; - Logging.LogGenericInfo(Bot.BotName, "Logging in to ISteamUserAuth..."); + Logging.LogGenericInfo("Logging in to ISteamUserAuth...", Bot.BotName); using (dynamic iSteamUserAuth = WebAPI.GetInterface("ISteamUserAuth")) { iSteamUserAuth.Timeout = Timeout; @@ -143,7 +143,7 @@ namespace ArchiSteamFarm { secure: true ); } catch (Exception e) { - Logging.LogGenericException(Bot.BotName, e); + Logging.LogGenericException(e, Bot.BotName); return false; } } @@ -152,7 +152,7 @@ namespace ArchiSteamFarm { return false; } - Logging.LogGenericInfo(Bot.BotName, "Success!"); + Logging.LogGenericInfo("Success!", Bot.BotName); string steamLogin = authResult["token"].AsString(); string steamLoginSecure = authResult["tokensecure"].AsString(); @@ -177,7 +177,7 @@ namespace ArchiSteamFarm { } if (htmlDocument == null) { - Logging.LogGenericWTF(Bot.BotName, "Request failed even after " + WebBrowser.MaxRetries + " tries"); + Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); return null; } @@ -188,7 +188,7 @@ namespace ArchiSteamFarm { internal async Task ReconnectIfNeeded() { bool? isLoggedIn = await IsLoggedIn().ConfigureAwait(false); if (isLoggedIn.HasValue && !isLoggedIn.Value) { - Logging.LogGenericInfo(Bot.BotName, "Reconnecting because our sessionID expired!"); + Logging.LogGenericInfo("Reconnecting because our sessionID expired!", Bot.BotName); var restart = Task.Run(async () => await Bot.Restart().ConfigureAwait(false)); return true; } @@ -213,13 +213,13 @@ namespace ArchiSteamFarm { secure: true ); } catch (Exception e) { - Logging.LogGenericException(Bot.BotName, e); + Logging.LogGenericException(e, Bot.BotName); } } } if (response == null) { - Logging.LogGenericWTF(Bot.BotName, "Request failed even after " + WebBrowser.MaxRetries + " tries"); + Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); return null; } @@ -293,7 +293,7 @@ namespace ArchiSteamFarm { } if (response == null) { - Logging.LogGenericWTF(Bot.BotName, "Request failed even after " + WebBrowser.MaxRetries + " tries"); + Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); return false; } @@ -323,7 +323,7 @@ namespace ArchiSteamFarm { } if (response == null) { - Logging.LogGenericWTF(Bot.BotName, "Request failed even after " + WebBrowser.MaxRetries + " tries"); + Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); return false; } @@ -355,7 +355,7 @@ namespace ArchiSteamFarm { } if (response == null) { - Logging.LogGenericWTF(Bot.BotName, "Request failed even after " + WebBrowser.MaxRetries + " tries"); + Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); return false; } @@ -379,13 +379,13 @@ namespace ArchiSteamFarm { secure: true ); } catch (Exception e) { - Logging.LogGenericException(Bot.BotName, e); + Logging.LogGenericException(e, Bot.BotName); } } } if (response == null) { - Logging.LogGenericWTF(Bot.BotName, "Request failed even after " + WebBrowser.MaxRetries + " tries"); + Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); return false; } @@ -399,7 +399,7 @@ namespace ArchiSteamFarm { } if (jObject == null) { - Logging.LogGenericWTF(Bot.BotName, "Request failed even after " + WebBrowser.MaxRetries + " tries"); + Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); return null; } @@ -464,7 +464,7 @@ namespace ArchiSteamFarm { } if (response == null) { - Logging.LogGenericWTF(Bot.BotName, "Request failed even after " + WebBrowser.MaxRetries + " tries"); + Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); return false; } } @@ -483,7 +483,7 @@ namespace ArchiSteamFarm { } if (htmlDocument == null) { - Logging.LogGenericWTF(Bot.BotName, "Request failed even after " + WebBrowser.MaxRetries + " tries"); + Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); return null; } @@ -501,7 +501,7 @@ namespace ArchiSteamFarm { } if (htmlDocument == null) { - Logging.LogGenericWTF(Bot.BotName, "Request failed even after " + WebBrowser.MaxRetries + " tries"); + Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName); return null; } diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 769b43c19..9461faadc 100644 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -124,12 +124,12 @@ namespace ArchiSteamFarm { bool initialized = false; while (!initialized) { try { - Logging.LogGenericInfo("Main", "Refreshing list of CMs..."); + Logging.LogGenericInfo("Refreshing list of CMs..."); SteamDirectory.Initialize().Wait(); initialized = true; - Logging.LogGenericInfo("Main", "Success!"); + Logging.LogGenericInfo("Success!"); } catch (TaskCanceledException) { - Logging.LogGenericWarning("Main", "Failed! Retrying..."); + Logging.LogGenericWarning("Failed! Retrying..."); } } } @@ -219,15 +219,15 @@ namespace ArchiSteamFarm { try { foreach (Confirmation confirmation in await SteamGuardAccount.FetchConfirmationsAsync().ConfigureAwait(false)) { if (SteamGuardAccount.AcceptConfirmation(confirmation)) { - Logging.LogGenericInfo(BotName, "Accepting confirmation: Success!"); + Logging.LogGenericInfo("Accepting confirmation: Success!", BotName); } else { - Logging.LogGenericWarning(BotName, "Accepting confirmation: Failed!"); + Logging.LogGenericWarning("Accepting confirmation: Failed!", BotName); } } } catch (SteamGuardAccount.WGTokenInvalidException) { - Logging.LogGenericWarning(BotName, "Accepting confirmation: Failed!"); - Logging.LogGenericWarning(BotName, "Confirmation could not be accepted because of invalid token exception"); - Logging.LogGenericWarning(BotName, "If issue persists, consider removing and readding ASF 2FA"); + Logging.LogGenericWarning("Accepting confirmation: Failed!", BotName); + Logging.LogGenericWarning("Confirmation could not be accepted because of invalid token exception", BotName); + Logging.LogGenericWarning("If issue persists, consider removing and readding ASF 2FA", BotName); } } @@ -236,7 +236,7 @@ namespace ArchiSteamFarm { return false; } - Logging.LogGenericNotice(BotName, "Linking new ASF MobileAuthenticator..."); + Logging.LogGenericInfo("Linking new ASF MobileAuthenticator...", BotName); UserLogin userLogin = new UserLogin(SteamLogin, SteamPassword); LoginResult loginResult; while ((loginResult = userLogin.DoLogin()) != LoginResult.LoginOkay) { @@ -245,7 +245,7 @@ namespace ArchiSteamFarm { userLogin.EmailCode = Program.GetUserInput(BotName, Program.EUserInputType.SteamGuard); break; default: - Logging.LogGenericError(BotName, "Unhandled situation: " + loginResult); + Logging.LogGenericError("Unhandled situation: " + loginResult, BotName); return false; } } @@ -259,7 +259,7 @@ namespace ArchiSteamFarm { authenticatorLinker.PhoneNumber = Program.GetUserInput(BotName, Program.EUserInputType.PhoneNumber); break; default: - Logging.LogGenericError(BotName, "Unhandled situation: " + linkResult); + Logging.LogGenericError("Unhandled situation: " + linkResult, BotName); return false; } } @@ -269,18 +269,18 @@ namespace ArchiSteamFarm { try { File.WriteAllText(MobileAuthenticatorFile, JsonConvert.SerializeObject(SteamGuardAccount)); } catch (Exception e) { - Logging.LogGenericException(BotName, e); + Logging.LogGenericException(e, BotName); return false; } AuthenticatorLinker.FinalizeResult finalizeResult = authenticatorLinker.FinalizeAddAuthenticator(Program.GetUserInput(BotName, Program.EUserInputType.SMS)); if (finalizeResult != AuthenticatorLinker.FinalizeResult.Success) { - Logging.LogGenericError(BotName, "Unhandled situation: " + finalizeResult); + Logging.LogGenericError("Unhandled situation: " + finalizeResult, BotName); DelinkMobileAuthenticator(); return false; } - Logging.LogGenericInfo(BotName, "Successfully linked ASF as new mobile authenticator for this account!"); + Logging.LogGenericInfo("Successfully linked ASF as new mobile authenticator for this account!", BotName); Program.GetUserInput(BotName, Program.EUserInputType.RevocationCode, SteamGuardAccount.RevocationCode); return true; } @@ -381,14 +381,14 @@ namespace ArchiSteamFarm { Statistics = bool.Parse(value); break; default: - Logging.LogGenericWarning(BotName, "Unrecognized config value: " + key + "=" + value); + Logging.LogGenericWarning("Unrecognized config value: " + key + "=" + value, BotName); break; } } } } catch (Exception e) { - Logging.LogGenericException(BotName, e); - Logging.LogGenericError(BotName, "Your config for this bot instance is invalid, it won't run!"); + Logging.LogGenericException(e, BotName); + Logging.LogGenericError("Your config for this bot instance is invalid, it won't run!", BotName); return false; } @@ -405,7 +405,7 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericInfo(BotName, "Starting..."); + Logging.LogGenericInfo("Starting...", BotName); // 2FA tokens are expiring soon, use limiter only when we don't have any pending if (TwoFactorAuth == null) { @@ -422,7 +422,7 @@ namespace ArchiSteamFarm { await Utilities.SleepAsync(0); // TODO: This is here only to make VS happy, for now - Logging.LogGenericInfo(BotName, "Stopping..."); + Logging.LogGenericInfo("Stopping...", BotName); SteamClient.Disconnect(); } @@ -593,7 +593,7 @@ namespace ArchiSteamFarm { try { result = await ArchiHandler.RedeemKey(key); } catch (Exception e) { - Logging.LogGenericException(BotName, e); + Logging.LogGenericException(e, BotName); break; } @@ -628,7 +628,7 @@ namespace ArchiSteamFarm { try { otherResult = await bot.ArchiHandler.RedeemKey(key); } catch (Exception e) { - Logging.LogGenericException(bot.BotName, e); + Logging.LogGenericException(e, bot.BotName); break; // We're done with this key } @@ -845,11 +845,11 @@ namespace ArchiSteamFarm { } if (callback.Result != EResult.OK) { - Logging.LogGenericError(BotName, "Unable to connect to Steam: " + callback.Result); + Logging.LogGenericError("Unable to connect to Steam: " + callback.Result, BotName); return; } - Logging.LogGenericInfo(BotName, "Connected to Steam!"); + Logging.LogGenericInfo("Connected to Steam!", BotName); if (File.Exists(LoginKeyFile)) { LoginKey = File.ReadAllText(LoginKeyFile); @@ -886,7 +886,7 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericInfo(BotName, "Disconnected from Steam!"); + Logging.LogGenericInfo("Disconnected from Steam!", BotName); await CardsFarmer.StopFarming().ConfigureAwait(false); if (!KeepRunning) { @@ -903,18 +903,18 @@ namespace ArchiSteamFarm { if (!string.IsNullOrEmpty(LoginKey)) { // InvalidPassword means usually that login key has expired, if we used it LoginKey = null; File.Delete(LoginKeyFile); - Logging.LogGenericInfo(BotName, "Removed expired login key"); + Logging.LogGenericInfo("Removed expired login key", BotName); } else { // If we didn't use login key, InvalidPassword usually means we got captcha or other network-based throttling - Logging.LogGenericInfo(BotName, "Will retry after 25 minutes..."); + Logging.LogGenericInfo("Will retry after 25 minutes...", BotName); await Utilities.SleepAsync(25 * 60 * 1000).ConfigureAwait(false); // Captcha disappears after around 20 minutes, so we make it 25 } } else if (LoggedInElsewhere) { LoggedInElsewhere = false; - Logging.LogGenericWarning(BotName, "Account is being used elsewhere, will try reconnecting in 30 minutes..."); + Logging.LogGenericWarning("Account is being used elsewhere, will try reconnecting in 30 minutes...", BotName); await Utilities.SleepAsync(30 * 60 * 1000).ConfigureAwait(false); } - Logging.LogGenericInfo(BotName, "Reconnecting..."); + Logging.LogGenericInfo("Reconnecting...", BotName); // 2FA tokens are expiring soon, use limiter only when we don't have any pending if (TwoFactorAuth == null) { @@ -1053,7 +1053,7 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericInfo(BotName, "Logged off of Steam: " + callback.Result); + Logging.LogGenericInfo("Logged off of Steam: " + callback.Result, BotName); switch (callback.Result) { case EResult.AlreadyLoggedInElsewhere: @@ -1083,10 +1083,10 @@ namespace ArchiSteamFarm { break; case EResult.InvalidPassword: InvalidPassword = true; - Logging.LogGenericWarning(BotName, "Unable to login to Steam: " + result); + Logging.LogGenericWarning("Unable to login to Steam: " + result, BotName); break; case EResult.OK: - Logging.LogGenericInfo(BotName, "Successfully logged on!"); + Logging.LogGenericInfo("Successfully logged on!", BotName); if (UseAsfAsMobileAuthenticator && TwoFactorAuth == null && SteamGuardAccount == null) { LinkMobileAuthenticator(); @@ -1127,10 +1127,10 @@ namespace ArchiSteamFarm { case EResult.ServiceUnavailable: case EResult.Timeout: case EResult.TryAnotherCM: - Logging.LogGenericWarning(BotName, "Unable to login to Steam: " + result); + Logging.LogGenericWarning("Unable to login to Steam: " + result, BotName); break; default: // Unexpected result, shutdown immediately - Logging.LogGenericWarning(BotName, "Unable to login to Steam: " + result); + Logging.LogGenericWarning("Unable to login to Steam: " + result, BotName); await Shutdown().ConfigureAwait(false); break; } diff --git a/ArchiSteamFarm/CardsFarmer.cs b/ArchiSteamFarm/CardsFarmer.cs index 247c5ad43..3990b4ccc 100755 --- a/ArchiSteamFarm/CardsFarmer.cs +++ b/ArchiSteamFarm/CardsFarmer.cs @@ -94,10 +94,10 @@ namespace ArchiSteamFarm { ManualMode = manualMode; if (ManualMode) { - Logging.LogGenericInfo(Bot.BotName, "Now running in Manual Farming mode"); + Logging.LogGenericInfo("Now running in Manual Farming mode", Bot.BotName); await StopFarming().ConfigureAwait(false); } else { - Logging.LogGenericInfo(Bot.BotName, "Now running in Automatic Farming mode"); + Logging.LogGenericInfo("Now running in Automatic Farming mode", Bot.BotName); var start = Task.Run(async () => await StartFarming().ConfigureAwait(false)); } } @@ -120,7 +120,7 @@ namespace ArchiSteamFarm { CurrentGamesFarming.Add(appID); } - Logging.LogGenericInfo(Bot.BotName, "Now farming: " + string.Join(", ", appIDs.Keys)); + Logging.LogGenericInfo("Now farming: " + string.Join(", ", appIDs.Keys), Bot.BotName); if (Farm(maxHour, appIDs.Keys)) { CurrentGamesFarming.Clear(); return true; @@ -138,7 +138,7 @@ namespace ArchiSteamFarm { CurrentGamesFarming.Clear(); CurrentGamesFarming.Add(appID); - Logging.LogGenericInfo(Bot.BotName, "Now farming: " + appID); + Logging.LogGenericInfo("Now farming: " + appID, Bot.BotName); if (await Farm(appID).ConfigureAwait(false)) { float hours; GamesToFarm.TryRemove(appID, out hours); @@ -167,20 +167,20 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericInfo(Bot.BotName, "We have a total of " + GamesToFarm.Count + " games to farm on this account..."); + Logging.LogGenericInfo("We have a total of " + GamesToFarm.Count + " games to farm on this account...", Bot.BotName); NowFarming = true; Semaphore.Release(); // From this point we allow other calls to shut us down // Now the algorithm used for farming depends on whether account is restricted or not if (Bot.CardDropsRestricted) { // If we have restricted card drops, we use complex algorithm - Logging.LogGenericInfo(Bot.BotName, "Chosen farming algorithm: Complex"); + Logging.LogGenericInfo("Chosen farming algorithm: Complex", Bot.BotName); while (GamesToFarm.Count > 0) { List gamesToFarmSolo = GetGamesToFarmSolo(GamesToFarm); if (gamesToFarmSolo.Count > 0) { while (gamesToFarmSolo.Count > 0) { uint appID = gamesToFarmSolo[0]; if (await FarmSolo(appID).ConfigureAwait(false)) { - Logging.LogGenericInfo(Bot.BotName, "Done farming: " + appID); + Logging.LogGenericInfo("Done farming: " + appID, Bot.BotName); gamesToFarmSolo.Remove(appID); } else { NowFarming = false; @@ -189,7 +189,7 @@ namespace ArchiSteamFarm { } } else { if (FarmMultiple(GamesToFarm)) { - Logging.LogGenericInfo(Bot.BotName, "Done farming: " + string.Join(", ", GamesToFarm.Keys)); + Logging.LogGenericInfo("Done farming: " + string.Join(", ", GamesToFarm.Keys), Bot.BotName); } else { NowFarming = false; return; @@ -197,11 +197,11 @@ namespace ArchiSteamFarm { } } } else { // If we have unrestricted card drops, we use simple algorithm - Logging.LogGenericInfo(Bot.BotName, "Chosen farming algorithm: Simple"); + Logging.LogGenericInfo("Chosen farming algorithm: Simple", Bot.BotName); while (GamesToFarm.Count > 0) { uint appID = GetAnyGameToFarm(GamesToFarm); if (await FarmSolo(appID).ConfigureAwait(false)) { - Logging.LogGenericInfo(Bot.BotName, "Done farming: " + appID); + Logging.LogGenericInfo("Done farming: " + appID, Bot.BotName); } else { NowFarming = false; return; @@ -211,7 +211,7 @@ namespace ArchiSteamFarm { CurrentGamesFarming.Clear(); NowFarming = false; - Logging.LogGenericInfo(Bot.BotName, "Farming finished!"); + Logging.LogGenericInfo("Farming finished!", Bot.BotName); await Bot.OnFarmingFinished().ConfigureAwait(false); } @@ -223,14 +223,14 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericInfo(Bot.BotName, "Sending signal to stop farming"); + Logging.LogGenericInfo("Sending signal to stop farming", Bot.BotName); FarmResetEvent.Set(); for (byte i = 0; i < 5 && NowFarming; i++) { - Logging.LogGenericInfo(Bot.BotName, "Waiting for reaction..."); + Logging.LogGenericInfo("Waiting for reaction...", Bot.BotName); await Utilities.SleepAsync(1000).ConfigureAwait(false); } FarmResetEvent.Reset(); - Logging.LogGenericInfo(Bot.BotName, "Farming stopped!"); + Logging.LogGenericInfo("Farming stopped!", Bot.BotName); Semaphore.Release(); } @@ -243,13 +243,13 @@ namespace ArchiSteamFarm { return false; } - Logging.LogGenericInfo(Bot.BotName, "Checking badges..."); + Logging.LogGenericInfo("Checking badges...", Bot.BotName); // Find the number of badge pages - Logging.LogGenericInfo(Bot.BotName, "Checking first page..."); + Logging.LogGenericInfo("Checking first page...", Bot.BotName); HtmlDocument htmlDocument = await Bot.ArchiWebHandler.GetBadgePage(1).ConfigureAwait(false); if (htmlDocument == null) { - Logging.LogGenericWarning(Bot.BotName, "Could not get badges information, will try again later!"); + Logging.LogGenericWarning("Could not get badges information, will try again later!", Bot.BotName); return false; } @@ -265,7 +265,7 @@ namespace ArchiSteamFarm { GamesToFarm.Clear(); // Find APPIDs we need to farm - Logging.LogGenericInfo(Bot.BotName, "Checking other pages..."); + Logging.LogGenericInfo("Checking other pages...", Bot.BotName); List checkPagesTasks = new List(); for (byte page = 1; page <= maxPages; page++) { @@ -285,7 +285,7 @@ namespace ArchiSteamFarm { // If we have restricted card drops, actually do check hours of all games that are left to farm if (Bot.CardDropsRestricted) { List checkHoursTasks = new List(); - Logging.LogGenericInfo(Bot.BotName, "Checking hours..."); + Logging.LogGenericInfo("Checking hours...", Bot.BotName); foreach (uint appID in GamesToFarm.Keys) { checkHoursTasks.Add(Task.Run(async () => await CheckHours(appID).ConfigureAwait(false))); } @@ -345,19 +345,19 @@ namespace ArchiSteamFarm { HtmlDocument htmlDocument = await Bot.ArchiWebHandler.GetGameCardsPage(appID).ConfigureAwait(false); if (htmlDocument == null) { - Logging.LogNullError(Bot.BotName, "htmlDocument"); + Logging.LogNullError("htmlDocument", Bot.BotName); return; } HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//div[@class='badge_title_stats_playtime']"); if (htmlNode == null) { - Logging.LogNullError(Bot.BotName, "htmlNode"); + Logging.LogNullError("htmlNode", Bot.BotName); return; } string hoursString = htmlNode.InnerText; if (string.IsNullOrEmpty(hoursString)) { - Logging.LogNullError(Bot.BotName, "hoursString"); + Logging.LogNullError("hoursString", Bot.BotName); return; } @@ -407,7 +407,7 @@ namespace ArchiSteamFarm { bool? keepFarming = await ShouldFarm(appID).ConfigureAwait(false); for (ushort farmingTime = 0; farmingTime <= MaxFarmingTime && (!keepFarming.HasValue || keepFarming.Value); farmingTime += StatusCheckSleep) { - Logging.LogGenericInfo(Bot.BotName, "Still farming: " + appID); + Logging.LogGenericInfo("Still farming: " + appID, Bot.BotName); if (FarmResetEvent.WaitOne(1000 * 60 * StatusCheckSleep)) { success = false; break; @@ -416,7 +416,7 @@ namespace ArchiSteamFarm { } Bot.ArchiHandler.PlayGames(0); - Logging.LogGenericInfo(Bot.BotName, "Stopped farming: " + appID); + Logging.LogGenericInfo("Stopped farming: " + appID, Bot.BotName); return success; } @@ -429,7 +429,7 @@ namespace ArchiSteamFarm { bool success = true; while (maxHour < 2) { - Logging.LogGenericInfo(Bot.BotName, "Still farming: " + string.Join(", ", appIDs)); + Logging.LogGenericInfo("Still farming: " + string.Join(", ", appIDs), Bot.BotName); if (FarmResetEvent.WaitOne(1000 * 60 * StatusCheckSleep)) { success = false; break; @@ -449,7 +449,7 @@ namespace ArchiSteamFarm { } Bot.ArchiHandler.PlayGames(0); - Logging.LogGenericInfo(Bot.BotName, "Stopped farming: " + string.Join(", ", appIDs)); + Logging.LogGenericInfo("Stopped farming: " + string.Join(", ", appIDs), Bot.BotName); return success; } } diff --git a/ArchiSteamFarm/Logging.cs b/ArchiSteamFarm/Logging.cs index 31aa6cb58..946da7ec9 100644 --- a/ArchiSteamFarm/Logging.cs +++ b/ArchiSteamFarm/Logging.cs @@ -56,46 +56,38 @@ namespace ArchiSteamFarm { } } - internal static void LogGenericWTF(string botName, string message, [CallerMemberName] string previousMethodName = "") { + internal static void LogGenericWTF(string message, string botName = "Main", [CallerMemberName] string previousMethodName = "") { Log("[!!] WTF: " + previousMethodName + "() <" + botName + "> " + message + ", WTF?"); } - internal static void LogGenericError(string botName, string message, [CallerMemberName] string previousMethodName = "") { + internal static void LogGenericError(string message, string botName = "Main", [CallerMemberName] string previousMethodName = "") { Log("[!!] ERROR: " + previousMethodName + "() <" + botName + "> " + message); } - internal static void LogGenericException(string botName, Exception exception, [CallerMemberName] string previousMethodName = "") { + internal static void LogGenericException(Exception exception, string botName = "Main", [CallerMemberName] string previousMethodName = "") { Log("[!] EXCEPTION: " + previousMethodName + "() <" + botName + "> " + exception.Message); Log("[!] StackTrace: " + exception.StackTrace); Exception innerException = exception.InnerException; if (innerException != null) { - LogGenericException(botName, innerException, previousMethodName); + LogGenericException(innerException, botName, previousMethodName); } } - internal static void LogGenericException(Exception exception, [CallerMemberName] string previousMethodName = "") { - LogGenericException("ASF", exception, previousMethodName); - } - - internal static void LogGenericWarning(string botName, string message, [CallerMemberName] string previousMethodName = "") { + internal static void LogGenericWarning(string message, string botName = "Main", [CallerMemberName] string previousMethodName = "") { Log("[!] WARNING: " + previousMethodName + "() <" + botName + "> " + message); } - internal static void LogGenericInfo(string botName, string message, [CallerMemberName] string previousMethodName = "") { + internal static void LogGenericInfo(string message, string botName = "Main", [CallerMemberName] string previousMethodName = "") { Log("[*] INFO: " + previousMethodName + "() <" + botName + "> " + message); } - internal static void LogGenericNotice(string botName, string message, [CallerMemberName] string previousMethodName = "") { - Log("[*] NOTICE: " + previousMethodName + "() <" + botName + "> " + message); - } - - internal static void LogNullError(string botName, string nullObjectName, [CallerMemberName] string previousMethodName = "") { - LogGenericError(botName, nullObjectName + " is null!", previousMethodName); + internal static void LogNullError(string nullObjectName, string botName = "Main", [CallerMemberName] string previousMethodName = "") { + LogGenericError(nullObjectName + " is null!", botName, previousMethodName); } [Conditional("DEBUG")] - internal static void LogGenericDebug(string botName, string message, [CallerMemberName] string previousMethodName = "") { + internal static void LogGenericDebug(string message, string botName = "Main", [CallerMemberName] string previousMethodName = "") { Log("[#] DEBUG: " + previousMethodName + "() <" + botName + "> " + message); } } diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index ed646725f..6ddffc8b6 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -79,17 +79,17 @@ namespace ArchiSteamFarm { string localVersion = Version; - Logging.LogGenericNotice("", "Local version: " + localVersion); - Logging.LogGenericNotice("", "Remote version: " + remoteVersion); + Logging.LogGenericInfo("Local version: " + localVersion); + Logging.LogGenericInfo("Remote version: " + remoteVersion); int comparisonResult = localVersion.CompareTo(remoteVersion); if (comparisonResult < 0) { - Logging.LogGenericNotice("", "New version is available!"); - Logging.LogGenericNotice("", "Consider updating yourself!"); + Logging.LogGenericInfo("New version is available!"); + Logging.LogGenericInfo("Consider updating yourself!"); await Utilities.SleepAsync(5000).ConfigureAwait(false); } else if (comparisonResult > 0) { - Logging.LogGenericNotice("", "You're currently using pre-release version!"); - Logging.LogGenericNotice("", "Be careful!"); + Logging.LogGenericInfo("You're currently using pre-release version!"); + Logging.LogGenericInfo("Be careful!"); } } @@ -152,7 +152,7 @@ namespace ArchiSteamFarm { internal static void OnBotShutdown() { if (Bot.GetRunningBotsCount() == 0) { - Logging.LogGenericInfo("Main", "No bots are running, exiting"); + Logging.LogGenericInfo("No bots are running, exiting"); ShutdownResetEvent.Set(); } } @@ -181,19 +181,19 @@ namespace ArchiSteamFarm { break; default: if (arg.StartsWith("--")) { - Logging.LogGenericWarning("Main", "Unrecognized parameter: " + arg); + Logging.LogGenericWarning("Unrecognized parameter: " + arg); continue; } if (Mode != EMode.Client) { - Logging.LogGenericWarning("Main", "Ignoring command because --client wasn't specified: " + arg); + Logging.LogGenericWarning("Ignoring command because --client wasn't specified: " + arg); continue; } - Logging.LogGenericNotice("WCF", "Command sent: \"" + arg + "\""); + Logging.LogGenericInfo("Command sent: \"" + arg + "\""); // We intentionally execute this async block synchronously - Logging.LogGenericNotice("WCF", "Response received: \"" + WCF.SendCommand(arg) + "\""); + Logging.LogGenericInfo("Response received: \"" + WCF.SendCommand(arg) + "\""); /* Task.Run(async () => { Logging.LogGenericNotice("WCF", "Response received: " + await WCF.SendCommand(arg).ConfigureAwait(false)); @@ -209,13 +209,13 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericException("Main", (Exception) args.ExceptionObject); + Logging.LogGenericException((Exception) args.ExceptionObject); } private static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler); - Logging.LogGenericInfo("Main", "Archi's Steam Farm, version " + Version); + Logging.LogGenericInfo("Archi's Steam Farm, version " + Version); Directory.SetCurrentDirectory(ExecutableDirectory); InitServices(); @@ -251,7 +251,7 @@ namespace ArchiSteamFarm { Task.Run(async () => await CheckForUpdate().ConfigureAwait(false)).Wait(); if (!Directory.Exists(ConfigDirectory)) { - Logging.LogGenericError("Main", "Config directory doesn't exist!"); + Logging.LogGenericError("Config directory doesn't exist!"); Thread.Sleep(5000); Task.Run(async () => await Exit(1).ConfigureAwait(false)).Wait(); } @@ -263,7 +263,7 @@ namespace ArchiSteamFarm { string botName = Path.GetFileNameWithoutExtension(configFile); Bot bot = new Bot(botName); if (!bot.Enabled) { - Logging.LogGenericInfo(botName, "Not starting this instance because it's disabled in config file"); + Logging.LogGenericInfo("Not starting this instance because it's disabled in config file", botName); } } diff --git a/ArchiSteamFarm/Trading.cs b/ArchiSteamFarm/Trading.cs index bac616722..bf3be6548 100644 --- a/ArchiSteamFarm/Trading.cs +++ b/ArchiSteamFarm/Trading.cs @@ -79,10 +79,10 @@ namespace ArchiSteamFarm { } if (tradeOffer.items_to_give.Count == 0 || tradeOffer.OtherSteamID64 == Bot.SteamMasterID) { - Logging.LogGenericInfo(Bot.BotName, "Accepting trade: " + tradeID); + Logging.LogGenericInfo("Accepting trade: " + tradeID, Bot.BotName); await Bot.ArchiWebHandler.AcceptTradeOffer(tradeID).ConfigureAwait(false); } else { - Logging.LogGenericInfo(Bot.BotName, "Ignoring trade: " + tradeID); + Logging.LogGenericInfo("Ignoring trade: " + tradeID, Bot.BotName); } } } diff --git a/ArchiSteamFarm/WCF.cs b/ArchiSteamFarm/WCF.cs index 185ae5fcf..d4d77e1a8 100644 --- a/ArchiSteamFarm/WCF.cs +++ b/ArchiSteamFarm/WCF.cs @@ -45,22 +45,22 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericNotice("WCF", "Starting WCF server..."); + Logging.LogGenericInfo("Starting WCF server..."); ServiceHost = new ServiceHost(typeof(WCF)); ServiceHost.AddServiceEndpoint(typeof(IWCF), new BasicHttpBinding(), URL); try { ServiceHost.Open(); } catch (AddressAccessDeniedException) { - Logging.LogGenericWarning("WCF", "WCF service could not be started because of AddressAccessDeniedException"); - Logging.LogGenericWarning("WCF", "If you want to use WCF service provided by ASF, consider starting ASF as administrator, or giving proper permissions"); + Logging.LogGenericWarning("WCF service could not be started because of AddressAccessDeniedException"); + Logging.LogGenericWarning("If you want to use WCF service provided by ASF, consider starting ASF as administrator, or giving proper permissions"); return; } catch (Exception e) { - Logging.LogGenericException("WCF", e); + Logging.LogGenericException(e); return; } - Logging.LogGenericNotice("WCF", "WCF server ready!"); + Logging.LogGenericInfo("WCF server ready!"); } internal void StopServer() { @@ -104,12 +104,12 @@ namespace ArchiSteamFarm { return "ERROR: Couldn't find any bot named: " + botName; } - Logging.LogGenericInfo("WCF", "Received command: \"" + input + "\""); + Logging.LogGenericInfo("Received command: \"" + input + "\""); string command = '!' + input; string output = bot.HandleMessage(command).Result; // TODO: This should be asynchronous - Logging.LogGenericInfo("WCF", "Answered to command: \"" + input + "\" with: \"" + output + "\""); + Logging.LogGenericInfo("Answered to command: \"" + input + "\" with: \"" + output + "\""); return output; } } @@ -121,7 +121,7 @@ namespace ArchiSteamFarm { try { return Channel.HandleCommand(input); } catch (Exception e) { - Logging.LogGenericException("WCF", e); + Logging.LogGenericException(e); return null; } }