Use one function to set log level

This commit is contained in:
Jack Ye 2025-03-12 12:26:29 +08:00
parent 11acca6215
commit 05ff797613
2 changed files with 19 additions and 15 deletions

View file

@ -63,16 +63,28 @@ namespace Flow.Launcher.Infrastructure.Logger
LogManager.Configuration = configuration;
}
public static void UseDebugLogLevel()
public static void SetLogLevel(LOGLEVEL level)
{
LogManager.Configuration.FindRuleByName("file").SetLoggingLevels(LogLevel.Debug, LogLevel.Fatal);
Info(nameof(Logger), "Using log level: DEBUG.");
switch (level)
{
case LOGLEVEL.DEBUG:
UseDebugLogLevel();
break;
default:
UseInfoLogLevel();
break;
}
Info(nameof(Logger), $"Using log level: {level}.");
}
public static void UseInfoLogLevel()
private static void UseDebugLogLevel()
{
LogManager.Configuration.FindRuleByName("file").SetLoggingLevels(LogLevel.Debug, LogLevel.Fatal);
}
private static void UseInfoLogLevel()
{
LogManager.Configuration.FindRuleByName("file").SetLoggingLevels(LogLevel.Info, LogLevel.Fatal);
Info(nameof(Logger), "Using log level: INFO.");
}
private static void LogFaultyFormat(string message)

View file

@ -112,6 +112,8 @@ namespace Flow.Launcher
{
await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
{
Log.SetLogLevel(_settings.LogLevel);
Ioc.Default.GetRequiredService<Portable>().PreStartCleanUpAfterPortabilityUpdate();
Log.Info("|App.OnStartup|Begin Flow Launcher startup ----------------------------------------------------");
@ -122,16 +124,6 @@ namespace Flow.Launcher
var imageLoadertask = ImageLoader.InitializeAsync();
switch (_settings.LogLevel)
{
case LOGLEVEL.DEBUG:
Log.UseDebugLogLevel();
break;
default:
Log.UseInfoLogLevel();
break;
}
AbstractPluginEnvironment.PreStartPluginExecutablePathUpdate(_settings);
// TODO: Clean InternationalizationManager.Instance and InternationalizationManager.Instance.GetTranslation in future