mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
Add support for logging/catching also very early messages
This commit is contained in:
@@ -39,35 +39,18 @@ namespace ArchiSteamFarm {
|
||||
private static readonly HashSet<LoggingRule> ConsoleLoggingRules = new HashSet<LoggingRule>();
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
internal static void Init() {
|
||||
private static bool IsUsingCustomConfiguration;
|
||||
|
||||
internal static void InitCoreLoggers() {
|
||||
if (LogManager.Configuration != null) {
|
||||
// User provided custom NLog config, or we have it set already, so don't override it
|
||||
IsUsingCustomConfiguration = true;
|
||||
InitConsoleLoggers();
|
||||
return;
|
||||
}
|
||||
|
||||
LoggingConfiguration config = new LoggingConfiguration();
|
||||
|
||||
if (Program.GlobalConfig.LogToFile) {
|
||||
FileTarget fileTarget = new FileTarget("File") {
|
||||
DeleteOldFileOnStartup = true,
|
||||
FileName = Program.LogFile,
|
||||
Layout = Layout
|
||||
};
|
||||
|
||||
config.AddTarget(fileTarget);
|
||||
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, fileTarget));
|
||||
}
|
||||
|
||||
if (Program.IsRunningAsService) {
|
||||
EventLogTarget eventLogTarget = new EventLogTarget("EventLog") {
|
||||
Layout = Layout
|
||||
};
|
||||
|
||||
config.AddTarget(eventLogTarget);
|
||||
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, eventLogTarget));
|
||||
}
|
||||
|
||||
ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget("Console") {
|
||||
Layout = Layout
|
||||
};
|
||||
@@ -79,6 +62,34 @@ namespace ArchiSteamFarm {
|
||||
InitConsoleLoggers();
|
||||
}
|
||||
|
||||
internal static void InitEnhancedLoggers() {
|
||||
if (IsUsingCustomConfiguration) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Program.GlobalConfig.LogToFile) {
|
||||
FileTarget fileTarget = new FileTarget("File") {
|
||||
DeleteOldFileOnStartup = true,
|
||||
FileName = Program.LogFile,
|
||||
Layout = Layout
|
||||
};
|
||||
|
||||
LogManager.Configuration.AddTarget(fileTarget);
|
||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, fileTarget));
|
||||
}
|
||||
|
||||
if (Program.IsRunningAsService) {
|
||||
EventLogTarget eventLogTarget = new EventLogTarget("EventLog") {
|
||||
Layout = Layout
|
||||
};
|
||||
|
||||
LogManager.Configuration.AddTarget(eventLogTarget);
|
||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, eventLogTarget));
|
||||
}
|
||||
|
||||
LogGenericInfo("Logging module initialized!");
|
||||
}
|
||||
|
||||
internal static void OnUserInputStart() {
|
||||
if (ConsoleLoggingRules.Count == 0) {
|
||||
return;
|
||||
|
||||
@@ -458,7 +458,9 @@ namespace ArchiSteamFarm {
|
||||
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
|
||||
TaskScheduler.UnobservedTaskException += UnobservedTaskExceptionHandler;
|
||||
|
||||
Logging.InitCoreLoggers();
|
||||
Logging.LogGenericInfo("ASF V" + Version);
|
||||
|
||||
Directory.SetCurrentDirectory(ExecutableDirectory);
|
||||
InitServices();
|
||||
|
||||
@@ -502,7 +504,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
// From now on it's server mode
|
||||
Logging.Init();
|
||||
Logging.InitEnhancedLoggers();
|
||||
|
||||
if (!Directory.Exists(ConfigDirectory)) {
|
||||
Logging.LogGenericError("Config directory doesn't exist!");
|
||||
|
||||
Reference in New Issue
Block a user