mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-05 16:41:01 +00:00
Gigantic code cleanup
Time to enforce some common file layout, as general mess started to annoying me. Sorry in advance for people using custom forks and having merge conflicts, this will help everybody in long-run
This commit is contained in:
@@ -29,9 +29,9 @@ using NLog.Targets;
|
||||
|
||||
namespace ArchiSteamFarm {
|
||||
internal static class Logging {
|
||||
private const string LayoutMessage = @"${logger}|${message}${onexception:inner= ${exception:format=toString,Data}}";
|
||||
private const string GeneralLayout = @"${date:format=yyyy-MM-dd HH\:mm\:ss}|${processname}-${processid}|${level:uppercase=true}|" + LayoutMessage;
|
||||
private const string EventLogLayout = LayoutMessage;
|
||||
private const string GeneralLayout = @"${date:format=yyyy-MM-dd HH\:mm\:ss}|${processname}-${processid}|${level:uppercase=true}|" + LayoutMessage;
|
||||
private const string LayoutMessage = @"${logger}|${message}${onexception:inner= ${exception:format=toString,Data}}";
|
||||
|
||||
private static readonly ConcurrentHashSet<LoggingRule> ConsoleLoggingRules = new ConcurrentHashSet<LoggingRule>();
|
||||
|
||||
@@ -47,29 +47,18 @@ namespace ArchiSteamFarm {
|
||||
|
||||
LoggingConfiguration config = new LoggingConfiguration();
|
||||
|
||||
ColoredConsoleTarget coloredConsoleTarget = new ColoredConsoleTarget("ColoredConsole") {
|
||||
DetectConsoleAvailable = false,
|
||||
Layout = GeneralLayout
|
||||
};
|
||||
ColoredConsoleTarget coloredConsoleTarget = new ColoredConsoleTarget("ColoredConsole") { DetectConsoleAvailable = false, Layout = GeneralLayout };
|
||||
|
||||
config.AddTarget(coloredConsoleTarget);
|
||||
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, coloredConsoleTarget));
|
||||
|
||||
if (Program.IsRunningAsService) {
|
||||
EventLogTarget eventLogTarget = new EventLogTarget("EventLog") {
|
||||
Layout = EventLogLayout,
|
||||
Log = SharedInfo.EventLog,
|
||||
Source = SharedInfo.EventLogSource
|
||||
};
|
||||
EventLogTarget eventLogTarget = new EventLogTarget("EventLog") { Layout = EventLogLayout, Log = SharedInfo.EventLog, Source = SharedInfo.EventLogSource };
|
||||
|
||||
config.AddTarget(eventLogTarget);
|
||||
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, eventLogTarget));
|
||||
} else if (!Program.Mode.HasFlag(Program.EMode.Client) || Program.Mode.HasFlag(Program.EMode.Server)) {
|
||||
FileTarget fileTarget = new FileTarget("File") {
|
||||
DeleteOldFileOnStartup = true,
|
||||
FileName = SharedInfo.LogFile,
|
||||
Layout = GeneralLayout
|
||||
};
|
||||
FileTarget fileTarget = new FileTarget("File") { DeleteOldFileOnStartup = true, FileName = SharedInfo.LogFile, Layout = GeneralLayout };
|
||||
|
||||
config.AddTarget(fileTarget);
|
||||
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, fileTarget));
|
||||
@@ -79,20 +68,6 @@ namespace ArchiSteamFarm {
|
||||
InitConsoleLoggers();
|
||||
}
|
||||
|
||||
internal static void OnUserInputStart() {
|
||||
IsWaitingForUserInput = true;
|
||||
|
||||
if (ConsoleLoggingRules.Count == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (LoggingRule consoleLoggingRule in ConsoleLoggingRules) {
|
||||
LogManager.Configuration.LoggingRules.Remove(consoleLoggingRule);
|
||||
}
|
||||
|
||||
LogManager.ReconfigExistingLoggers();
|
||||
}
|
||||
|
||||
internal static void OnUserInputEnd() {
|
||||
IsWaitingForUserInput = false;
|
||||
|
||||
@@ -107,6 +82,20 @@ namespace ArchiSteamFarm {
|
||||
LogManager.ReconfigExistingLoggers();
|
||||
}
|
||||
|
||||
internal static void OnUserInputStart() {
|
||||
IsWaitingForUserInput = true;
|
||||
|
||||
if (ConsoleLoggingRules.Count == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (LoggingRule consoleLoggingRule in ConsoleLoggingRules) {
|
||||
LogManager.Configuration.LoggingRules.Remove(consoleLoggingRule);
|
||||
}
|
||||
|
||||
LogManager.ReconfigExistingLoggers();
|
||||
}
|
||||
|
||||
private static void InitConsoleLoggers() {
|
||||
ConsoleLoggingRules.Clear();
|
||||
foreach (LoggingRule loggingRule in LogManager.Configuration.LoggingRules.Where(loggingRule => loggingRule.Targets.Any(target => target is ColoredConsoleTarget || target is ConsoleTarget))) {
|
||||
@@ -127,4 +116,4 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user