mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 06:00:46 +00:00
Enhance startup sequence a bit
This commit is contained in:
@@ -41,12 +41,11 @@ namespace ArchiSteamFarm {
|
||||
private static readonly ConcurrentHashSet<LoggingRule> ConsoleLoggingRules = new ConcurrentHashSet<LoggingRule>();
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private static bool IsUsingCustomConfiguration, IsWaitingForUserInput;
|
||||
private static bool IsWaitingForUserInput;
|
||||
|
||||
internal static void InitCoreLoggers() {
|
||||
internal static void InitLoggers() {
|
||||
if (LogManager.Configuration != null) {
|
||||
// User provided custom NLog config, or we have it set already, so don't override it
|
||||
IsUsingCustomConfiguration = true;
|
||||
InitConsoleLoggers();
|
||||
LogManager.ConfigurationChanged += OnConfigurationChanged;
|
||||
return;
|
||||
@@ -61,15 +60,6 @@ namespace ArchiSteamFarm {
|
||||
config.AddTarget(consoleTarget);
|
||||
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget));
|
||||
|
||||
LogManager.Configuration = config;
|
||||
InitConsoleLoggers();
|
||||
}
|
||||
|
||||
internal static void InitEnhancedLoggers() {
|
||||
if (IsUsingCustomConfiguration) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Program.IsRunningAsService) {
|
||||
EventLogTarget eventLogTarget = new EventLogTarget("EventLog") {
|
||||
Layout = EventLogLayout,
|
||||
@@ -77,21 +67,21 @@ namespace ArchiSteamFarm {
|
||||
Source = SharedInfo.EventLogSource
|
||||
};
|
||||
|
||||
LogManager.Configuration.AddTarget(eventLogTarget);
|
||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, eventLogTarget));
|
||||
} else {
|
||||
config.AddTarget(eventLogTarget);
|
||||
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, eventLogTarget));
|
||||
} else if (Program.Mode != Program.EMode.Client) {
|
||||
FileTarget fileTarget = new FileTarget("File") {
|
||||
DeleteOldFileOnStartup = true,
|
||||
FileName = SharedInfo.LogFile,
|
||||
Layout = GeneralLayout
|
||||
};
|
||||
|
||||
LogManager.Configuration.AddTarget(fileTarget);
|
||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, fileTarget));
|
||||
config.AddTarget(fileTarget);
|
||||
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, fileTarget));
|
||||
}
|
||||
|
||||
LogManager.ReconfigExistingLoggers();
|
||||
LogGenericInfo("Logging module initialized!");
|
||||
LogManager.Configuration = config;
|
||||
InitConsoleLoggers();
|
||||
}
|
||||
|
||||
internal static void OnUserInputStart() {
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -35,9 +34,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ArchiSteamFarm {
|
||||
internal static class Program {
|
||||
private enum EMode : byte {
|
||||
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||
Unknown,
|
||||
internal enum EMode : byte {
|
||||
Normal, // Standard most common usage
|
||||
Client, // WCF client only
|
||||
Server // Normal + WCF server
|
||||
@@ -50,12 +47,11 @@ namespace ArchiSteamFarm {
|
||||
|
||||
internal static bool IsRunningAsService { get; private set; }
|
||||
internal static bool ShutdownSequenceInitialized { get; private set; }
|
||||
internal static EMode Mode { get; private set; } = EMode.Normal;
|
||||
internal static GlobalConfig GlobalConfig { get; private set; }
|
||||
internal static GlobalDatabase GlobalDatabase { get; private set; }
|
||||
internal static WebBrowser WebBrowser { get; private set; }
|
||||
|
||||
private static EMode Mode = EMode.Normal;
|
||||
|
||||
internal static void Exit(byte exitCode = 0) {
|
||||
Shutdown();
|
||||
Environment.Exit(exitCode);
|
||||
@@ -194,6 +190,12 @@ namespace ArchiSteamFarm {
|
||||
switch (arg) {
|
||||
case "":
|
||||
break;
|
||||
case "--client":
|
||||
Mode = EMode.Client;
|
||||
break;
|
||||
case "--server":
|
||||
Mode = EMode.Server;
|
||||
break;
|
||||
default:
|
||||
if (arg.StartsWith("--", StringComparison.Ordinal)) {
|
||||
if (arg.StartsWith("--path=", StringComparison.Ordinal) && (arg.Length > 7)) {
|
||||
@@ -288,7 +290,12 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
}
|
||||
|
||||
Logging.InitCoreLoggers();
|
||||
// Parse pre-init args
|
||||
if (args != null) {
|
||||
ParsePreInitArgs(args);
|
||||
}
|
||||
|
||||
Logging.InitLoggers();
|
||||
Logging.LogGenericInfo("ASF V" + SharedInfo.Version);
|
||||
|
||||
if (!Runtime.IsRuntimeSupported) {
|
||||
@@ -296,11 +303,6 @@ namespace ArchiSteamFarm {
|
||||
Thread.Sleep(10000);
|
||||
}
|
||||
|
||||
// Parse pre-init args
|
||||
if (args != null) {
|
||||
ParsePreInitArgs(args);
|
||||
}
|
||||
|
||||
InitServices();
|
||||
|
||||
// If debugging is on, we prepare debug directory prior to running
|
||||
@@ -326,8 +328,6 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
// From now on it's server mode
|
||||
Logging.InitEnhancedLoggers();
|
||||
|
||||
if (!Directory.Exists(SharedInfo.ConfigDirectory)) {
|
||||
Logging.LogGenericError("Config directory doesn't exist!");
|
||||
Thread.Sleep(5000);
|
||||
|
||||
Reference in New Issue
Block a user