Add internal logging, closes #44

This commit is contained in:
JustArchi
2015-12-21 10:19:47 +01:00
parent f484b50ab3
commit 3f7660526d
2 changed files with 22 additions and 4 deletions

View File

@@ -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 = "") {

View File

@@ -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