mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 06:00:46 +00:00
Add internal logging, closes #44
This commit is contained in:
@@ -24,16 +24,32 @@
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ArchiSteamFarm {
|
||||
internal static class Logging {
|
||||
private static readonly object FileLock = new object();
|
||||
|
||||
internal static void Init() {
|
||||
File.Delete(Program.LogFile);
|
||||
}
|
||||
|
||||
private static void Log(string message) {
|
||||
if (Program.ConsoleIsBusy) {
|
||||
if (string.IsNullOrEmpty(message)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine(DateTime.Now + " " + message);
|
||||
string loggedMessage = DateTime.Now + " " + message + Environment.NewLine;
|
||||
|
||||
// Write on console only when not awaiting response from user
|
||||
if (!Program.ConsoleIsBusy) {
|
||||
Console.Write(loggedMessage);
|
||||
}
|
||||
|
||||
lock (FileLock) {
|
||||
File.AppendAllText(Program.LogFile, loggedMessage);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void LogGenericError(string botName, string message, [CallerMemberName] string previousMethodName = "") {
|
||||
|
||||
@@ -53,6 +53,7 @@ namespace ArchiSteamFarm {
|
||||
private static readonly object ConsoleLock = new object();
|
||||
//private static readonly string ExeName = AssemblyName.Name + ".exe";
|
||||
|
||||
internal static readonly string LogFile = Path.Combine(Path.GetDirectoryName(ExecutablePath), "log.txt");
|
||||
internal static readonly string Version = AssemblyName.Version.ToString();
|
||||
|
||||
internal static bool ConsoleIsBusy { get; private set; } = false;
|
||||
@@ -150,14 +151,15 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
private static void InitServices() {
|
||||
Logging.Init();
|
||||
WebBrowser.Init();
|
||||
}
|
||||
|
||||
private static void Main(string[] args) {
|
||||
Logging.LogGenericInfo("Main", "Archi's Steam Farm, version " + Version);
|
||||
|
||||
InitServices();
|
||||
|
||||
Logging.LogGenericInfo("Main", "Archi's Steam Farm, version " + Version);
|
||||
|
||||
Task.Run(async () => await CheckForUpdate().ConfigureAwait(false)).Wait();
|
||||
|
||||
// Allow loading configs from source tree if it's a debug build
|
||||
|
||||
Reference in New Issue
Block a user