mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 06:00:46 +00:00
Address missed NLog breaking change
This commit is contained in:
@@ -34,7 +34,6 @@ using ArchiSteamFarm.NLog.Targets;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NLog.Web;
|
||||
@@ -76,14 +75,6 @@ internal static class ArchiKestrel {
|
||||
// Set default content root
|
||||
builder.UseContentRoot(SharedInfo.HomeDirectory);
|
||||
|
||||
// Firstly initialize settings that user is free to override
|
||||
builder.ConfigureLogging(
|
||||
static logging => {
|
||||
logging.ClearProviders();
|
||||
logging.SetMinimumLevel(Debugging.IsUserDebugging ? LogLevel.Trace : LogLevel.Warning);
|
||||
}
|
||||
);
|
||||
|
||||
// Check if custom config is available
|
||||
string absoluteConfigDirectory = Path.Combine(Directory.GetCurrentDirectory(), SharedInfo.ConfigDirectory);
|
||||
string customConfigPath = Path.Combine(absoluteConfigDirectory, SharedInfo.IPCConfigFile);
|
||||
@@ -104,9 +95,6 @@ internal static class ArchiKestrel {
|
||||
ASF.ArchiLogger.LogGenericException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Use custom config for logging configuration
|
||||
builder.ConfigureLogging(static (hostingContext, logging) => logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging")));
|
||||
}
|
||||
|
||||
// Enable NLog integration for logging
|
||||
|
||||
@@ -186,8 +186,7 @@ internal static class Logging {
|
||||
};
|
||||
#pragma warning restore CA2000 // False positive, we're adding this disposable object to the global scope, so we can't dispose it
|
||||
|
||||
LogManager.Configuration.AddTarget(fileTarget);
|
||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, fileTarget));
|
||||
InitializeTarget(LogManager.Configuration, fileTarget);
|
||||
|
||||
LogManager.ReconfigExistingLoggers();
|
||||
}
|
||||
@@ -210,8 +209,7 @@ internal static class Logging {
|
||||
ColoredConsoleTarget coloredConsoleTarget = new("ColoredConsole") { Layout = GeneralLayout };
|
||||
#pragma warning restore CA2000 // False positive, we're adding this disposable object to the global scope, so we can't dispose it
|
||||
|
||||
config.AddTarget(coloredConsoleTarget);
|
||||
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, coloredConsoleTarget));
|
||||
InitializeTarget(config, coloredConsoleTarget);
|
||||
|
||||
LogManager.Configuration = config;
|
||||
}
|
||||
@@ -229,8 +227,7 @@ internal static class Logging {
|
||||
MaxCount = 20
|
||||
};
|
||||
|
||||
LogManager.Configuration.AddTarget(historyTarget);
|
||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, historyTarget));
|
||||
InitializeTarget(LogManager.Configuration, historyTarget);
|
||||
|
||||
LogManager.ReconfigExistingLoggers();
|
||||
}
|
||||
@@ -396,6 +393,22 @@ internal static class Logging {
|
||||
}
|
||||
}
|
||||
|
||||
private static void InitializeTarget(LoggingConfiguration config, Target target) {
|
||||
ArgumentNullException.ThrowIfNull(config);
|
||||
ArgumentNullException.ThrowIfNull(target);
|
||||
|
||||
config.AddTarget(target);
|
||||
|
||||
if (!Debugging.IsUserDebugging) {
|
||||
// Silence default ASP.NET logging
|
||||
config.LoggingRules.Add(new LoggingRule("Microsoft*", target) { FinalMinLevel = LogLevel.Warn });
|
||||
config.LoggingRules.Add(new LoggingRule("Microsoft.Hosting.Lifetime*", target) { FinalMinLevel = LogLevel.Info });
|
||||
config.LoggingRules.Add(new LoggingRule("System*", target) { FinalMinLevel = LogLevel.Warn });
|
||||
}
|
||||
|
||||
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, target));
|
||||
}
|
||||
|
||||
private static void OnConfigurationChanged(object? sender, LoggingConfigurationChangedEventArgs e) {
|
||||
ArgumentNullException.ThrowIfNull(e);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user