Skip to content

Commit ec151c3

Browse files
committed
Ensure rare console writes leave trace in the log as of what is happening
1 parent 05079eb commit ec151c3

File tree

1 file changed

+58
-11
lines changed

1 file changed

+58
-11
lines changed

ArchiSteamFarm/NLog/Logging.cs

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,24 @@ internal static void EnableTraceLogging() {
9696
OnUserInputStart();
9797

9898
try {
99+
// Since we're in the user input section, logging to NLog will not spam our console targets, but will still leave appropriate trace e.g. in the file targets
99100
switch (userInputType) {
100101
case ASF.EUserInputType.Cryptkey:
101-
Console.Write(Bot.FormatBotResponse(Strings.UserInputCryptkey, botName));
102+
string cryptKeyText = Bot.FormatBotResponse(Strings.UserInputCryptkey, botName);
103+
104+
ASF.ArchiLogger.LogGenericWarning(cryptKeyText);
105+
106+
Console.Write(cryptKeyText);
102107
result = ConsoleReadLineMasked();
103108

104109
break;
105110
case ASF.EUserInputType.DeviceConfirmation:
111+
string deviceConfirmationText = Bot.FormatBotResponse(Strings.UserInputDeviceConfirmation, botName);
112+
106113
while (true) {
107-
Console.Write(Bot.FormatBotResponse(Strings.UserInputDeviceConfirmation, botName));
114+
ASF.ArchiLogger.LogGenericWarning(deviceConfirmationText);
115+
116+
Console.Write(deviceConfirmationText);
108117
result = ConsoleReadLine();
109118

110119
if (string.IsNullOrEmpty(result) || result.Equals("Y", StringComparison.OrdinalIgnoreCase) || result.Equals("N", StringComparison.OrdinalIgnoreCase)) {
@@ -114,27 +123,47 @@ internal static void EnableTraceLogging() {
114123

115124
break;
116125
case ASF.EUserInputType.Login:
117-
Console.Write(Bot.FormatBotResponse(Strings.UserInputSteamLogin, botName));
126+
string loginText = Bot.FormatBotResponse(Strings.UserInputSteamLogin, botName);
127+
128+
ASF.ArchiLogger.LogGenericWarning(loginText);
129+
130+
Console.Write(loginText);
118131
result = ConsoleReadLine();
119132

120133
break;
121134
case ASF.EUserInputType.Password:
122-
Console.Write(Bot.FormatBotResponse(Strings.UserInputSteamPassword, botName));
135+
string passwordText = Bot.FormatBotResponse(Strings.UserInputSteamPassword, botName);
136+
137+
ASF.ArchiLogger.LogGenericWarning(passwordText);
138+
139+
Console.Write(passwordText);
123140
result = ConsoleReadLineMasked();
124141

125142
break;
126143
case ASF.EUserInputType.SteamGuard:
127-
Console.Write(Bot.FormatBotResponse(Strings.UserInputSteamGuard, botName));
144+
string steamGuardText = Bot.FormatBotResponse(Strings.UserInputSteamGuard, botName);
145+
146+
ASF.ArchiLogger.LogGenericWarning(steamGuardText);
147+
148+
Console.Write(steamGuardText);
128149
result = ConsoleReadLine();
129150

130151
break;
131152
case ASF.EUserInputType.SteamParentalCode:
132-
Console.Write(Bot.FormatBotResponse(Strings.UserInputSteamParentalCode, botName));
153+
string steamParentalCodeText = Bot.FormatBotResponse(Strings.UserInputSteamParentalCode, botName);
154+
155+
ASF.ArchiLogger.LogGenericWarning(steamParentalCodeText);
156+
157+
Console.Write(steamParentalCodeText);
133158
result = ConsoleReadLineMasked();
134159

135160
break;
136161
case ASF.EUserInputType.TwoFactorAuthentication:
137-
Console.Write(Bot.FormatBotResponse(Strings.UserInputSteam2FA, botName));
162+
string twoFactorAuthenticationText = Bot.FormatBotResponse(Strings.UserInputSteam2FA, botName);
163+
164+
ASF.ArchiLogger.LogGenericWarning(twoFactorAuthenticationText);
165+
166+
Console.Write(twoFactorAuthenticationText);
138167
result = ConsoleReadLine();
139168

140169
break;
@@ -386,7 +415,12 @@ private static async Task HandleConsoleInteractively() {
386415
OnUserInputStart();
387416

388417
try {
389-
Console.Write($@">> {Strings.EnterCommand}");
418+
// Since we're in the user input section, logging to NLog will not spam our console targets, but will still leave appropriate trace e.g. in the file targets
419+
string enterCommandText = $@">> {Strings.EnterCommand}";
420+
421+
ASF.ArchiLogger.LogGenericInfo(enterCommandText);
422+
423+
Console.Write(enterCommandText);
390424
string? command = ConsoleReadLine();
391425

392426
if (string.IsNullOrEmpty(command)) {
@@ -407,7 +441,11 @@ private static async Task HandleConsoleInteractively() {
407441
Bot? targetBot = Bot.GetDefaultBot();
408442

409443
if (targetBot == null) {
410-
Console.WriteLine($@"<< {Strings.ErrorNoBotsDefined}");
444+
string noBotsDefinedText = $@"<< {Strings.ErrorNoBotsDefined}";
445+
446+
ASF.ArchiLogger.LogGenericInfo(noBotsDefinedText);
447+
448+
Console.WriteLine(noBotsDefinedText);
411449

412450
continue;
413451
}
@@ -418,12 +456,21 @@ private static async Task HandleConsoleInteractively() {
418456

419457
if (string.IsNullOrEmpty(response)) {
420458
ASF.ArchiLogger.LogNullError(response);
421-
Console.WriteLine(Strings.ErrorIsEmpty, nameof(response));
459+
460+
string emptyResponseText = $@"<< {Strings.FormatErrorIsEmpty(nameof(response))}";
461+
462+
ASF.ArchiLogger.LogGenericInfo(emptyResponseText);
463+
464+
Console.WriteLine(emptyResponseText);
422465

423466
continue;
424467
}
425468

426-
Console.WriteLine($@"<< {response}");
469+
string responseText = $@"<< {response}";
470+
471+
ASF.ArchiLogger.LogGenericInfo(responseText);
472+
473+
Console.WriteLine(responseText);
427474
} finally {
428475
OnUserInputEnd();
429476
}

0 commit comments

Comments
 (0)