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