mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2025-12-20 16:28:38 +00:00
Integrate DebugListener with Logger
This commit is contained in:
@@ -23,9 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using SteamKit2;
|
using SteamKit2;
|
||||||
using System;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace ArchiSteamFarm {
|
namespace ArchiSteamFarm {
|
||||||
internal static class Debugging {
|
internal static class Debugging {
|
||||||
@@ -38,30 +36,13 @@ namespace ArchiSteamFarm {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
internal sealed class DebugListener : IDebugListener {
|
internal sealed class DebugListener : IDebugListener {
|
||||||
private readonly object FileLock = new object();
|
|
||||||
private readonly string FilePath;
|
|
||||||
|
|
||||||
internal DebugListener(string filePath) {
|
|
||||||
if (string.IsNullOrEmpty(filePath)) {
|
|
||||||
throw new ArgumentNullException(nameof(filePath));
|
|
||||||
}
|
|
||||||
|
|
||||||
FilePath = filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WriteLine(string category, string msg) {
|
public void WriteLine(string category, string msg) {
|
||||||
if (string.IsNullOrEmpty(category) && string.IsNullOrEmpty(msg)) {
|
if (string.IsNullOrEmpty(category) && string.IsNullOrEmpty(msg)) {
|
||||||
Logging.LogNullError(nameof(category) + " && " + nameof(msg));
|
Logging.LogNullError(nameof(category) + " && " + nameof(msg));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lock (FileLock) {
|
Logging.LogGenericDebug(category + " | " + msg, "DebugListener");
|
||||||
try {
|
|
||||||
File.AppendAllText(FilePath, category + " | " + msg + Environment.NewLine);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Logging.LogGenericException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -184,7 +183,6 @@ namespace ArchiSteamFarm {
|
|||||||
LogGenericError(nullObjectName + " is null!", botName, previousMethodName);
|
LogGenericError(nullObjectName + " is null!", botName, previousMethodName);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Conditional("DEBUG")]
|
|
||||||
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||||
internal static void LogGenericDebug(string message, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) {
|
internal static void LogGenericDebug(string message, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) {
|
||||||
if (string.IsNullOrEmpty(message)) {
|
if (string.IsNullOrEmpty(message)) {
|
||||||
|
|||||||
@@ -311,9 +311,10 @@ namespace ArchiSteamFarm {
|
|||||||
Directory.Delete(SharedInfo.DebugDirectory, true);
|
Directory.Delete(SharedInfo.DebugDirectory, true);
|
||||||
Thread.Sleep(1000); // Dirty workaround giving Windows some time to sync
|
Thread.Sleep(1000); // Dirty workaround giving Windows some time to sync
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(SharedInfo.DebugDirectory);
|
Directory.CreateDirectory(SharedInfo.DebugDirectory);
|
||||||
|
|
||||||
SteamKit2.DebugLog.AddListener(new Debugging.DebugListener(Path.Combine(SharedInfo.DebugDirectory, "debug.txt")));
|
SteamKit2.DebugLog.AddListener(new Debugging.DebugListener());
|
||||||
SteamKit2.DebugLog.Enabled = true;
|
SteamKit2.DebugLog.Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -172,7 +171,6 @@ namespace ArchiSteamFarm {
|
|||||||
LogGenericError(nullObjectName + " is null!", botName, previousMethodName);
|
LogGenericError(nullObjectName + " is null!", botName, previousMethodName);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Conditional("DEBUG")]
|
|
||||||
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||||
internal static void LogGenericDebug(string message, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) {
|
internal static void LogGenericDebug(string message, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) {
|
||||||
if (string.IsNullOrEmpty(message)) {
|
if (string.IsNullOrEmpty(message)) {
|
||||||
|
|||||||
@@ -126,9 +126,10 @@ namespace ArchiSteamFarm {
|
|||||||
Directory.Delete(SharedInfo.DebugDirectory, true);
|
Directory.Delete(SharedInfo.DebugDirectory, true);
|
||||||
Thread.Sleep(1000); // Dirty workaround giving Windows some time to sync
|
Thread.Sleep(1000); // Dirty workaround giving Windows some time to sync
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(SharedInfo.DebugDirectory);
|
Directory.CreateDirectory(SharedInfo.DebugDirectory);
|
||||||
|
|
||||||
SteamKit2.DebugLog.AddListener(new Debugging.DebugListener(Path.Combine(SharedInfo.DebugDirectory, "debug.txt")));
|
SteamKit2.DebugLog.AddListener(new Debugging.DebugListener());
|
||||||
SteamKit2.DebugLog.Enabled = true;
|
SteamKit2.DebugLog.Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user