diff --git a/src/Common.CoreLib/Log.cs b/src/Common.CoreLib/Log.cs index 772627f2b..51e94932d 100644 --- a/src/Common.CoreLib/Log.cs +++ b/src/Common.CoreLib/Log.cs @@ -11,7 +11,11 @@ namespace System; /// public static class Log { - internal static ILoggerFactory Factory => DI.Get(); + public static Func? LoggerFactory { private get; set; } + + static ILoggerFactory? factory; + + public static ILoggerFactory Factory => factory ??= DI.Get_Nullable() ?? LoggerFactory?.Invoke() ?? throw new ArgumentNullException(nameof(LoggerFactory)); public static ILogger CreateLogger(string tag) => Factory.CreateLogger(tag); diff --git a/src/ST.Client.Desktop.Avalonia.App/Program.cs b/src/ST.Client.Desktop.Avalonia.App/Program.cs index 66f348dd2..975785198 100644 --- a/src/ST.Client.Desktop.Avalonia.App/Program.cs +++ b/src/ST.Client.Desktop.Avalonia.App/Program.cs @@ -77,6 +77,7 @@ namespace System.Application.UI // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) PlatformApp?.Dispose(); DI.Dispose(); + LogManager.Shutdown(); } } diff --git a/src/ST.Client/UI/IApplication.Log.cs b/src/ST.Client/UI/IApplication.Log.cs index a9d1678ff..dbf5db790 100644 --- a/src/ST.Client/UI/IApplication.Log.cs +++ b/src/ST.Client/UI/IApplication.Log.cs @@ -248,6 +248,8 @@ namespace System.Application.UI } config.LoggingRules.Add(new LoggingRule("*", minLevel, target)); } + + Log.LoggerFactory = () => new LoggerFactory(new[] { new NLogLoggerProvider() }); } #endregion