Fix HistoryTarget when using custom NLog configuration

This commit is contained in:
JustArchi
2018-07-24 20:37:14 +02:00
parent 60d84c0300
commit eb656f26f3

View File

@@ -80,20 +80,31 @@ namespace ArchiSteamFarm {
}
internal static void InitHistoryLogger() {
if (IsUsingCustomConfiguration || (LogManager.Configuration == null)) {
if (LogManager.Configuration == null) {
return;
}
// TODO: We could use some nice HTML layout for this
HistoryTarget historyTarget = new HistoryTarget("History") {
Layout = GeneralLayout,
MaxCount = 20
};
HistoryTarget historyTarget;
LogManager.Configuration.AddTarget(historyTarget);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, historyTarget));
if (IsUsingCustomConfiguration) {
historyTarget = LogManager.Configuration.AllTargets.OfType<HistoryTarget>().FirstOrDefault();
if (historyTarget == null) {
return;
}
} else {
// TODO: We could use some nice HTML layout for this
historyTarget = new HistoryTarget("History") {
Layout = GeneralLayout,
MaxCount = 20
};
LogManager.Configuration.AddTarget(historyTarget);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, historyTarget));
LogManager.ReconfigExistingLoggers();
}
LogManager.ReconfigExistingLoggers();
IPC.OnNewHistoryTarget(historyTarget);
}
@@ -163,4 +174,4 @@ namespace ArchiSteamFarm {
}
}
}
}
}