From 05ff797613c952aedde47a1cfc55efe924ab6682 Mon Sep 17 00:00:00 2001 From: Jack Ye <1160210343@qq.com> Date: Wed, 12 Mar 2025 12:26:29 +0800 Subject: [PATCH] Use one function to set log level --- Flow.Launcher.Infrastructure/Logger/Log.cs | 22 +++++++++++++++++----- Flow.Launcher/App.xaml.cs | 12 ++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Logger/Log.cs b/Flow.Launcher.Infrastructure/Logger/Log.cs index 2f368ac0c..7f847e287 100644 --- a/Flow.Launcher.Infrastructure/Logger/Log.cs +++ b/Flow.Launcher.Infrastructure/Logger/Log.cs @@ -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) diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index ec4bb8dc6..ab68cf426 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -112,6 +112,8 @@ namespace Flow.Launcher { await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () => { + Log.SetLogLevel(_settings.LogLevel); + Ioc.Default.GetRequiredService().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