From ca90347dc242e7dc5e49e6fb8938e084564ab2de Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Sun, 6 Sep 2026 07:46:18 +0200 Subject: Resolve migration routine loggers from the application container --- Jellyfin.Server/ServerSetupApp/StartupLogger.cs | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'Jellyfin.Server/ServerSetupApp') diff --git a/Jellyfin.Server/ServerSetupApp/StartupLogger.cs b/Jellyfin.Server/ServerSetupApp/StartupLogger.cs index 0121854ce3..b72b0c0eab 100644 --- a/Jellyfin.Server/ServerSetupApp/StartupLogger.cs +++ b/Jellyfin.Server/ServerSetupApp/StartupLogger.cs @@ -1,5 +1,6 @@ using System; using System.Globalization; +using System.Threading; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -8,6 +9,8 @@ namespace Jellyfin.Server.ServerSetupApp; /// public class StartupLogger : IStartupLogger { + private static readonly AsyncLocal _ambientTopic = new(); + private readonly StartupLogTopic? _topic; /// @@ -17,6 +20,7 @@ public class StartupLogger : IStartupLogger public StartupLogger(ILogger logger) { BaseLogger = logger; + _topic = _ambientTopic.Value; } /// @@ -39,6 +43,18 @@ public class StartupLogger : IStartupLogger /// protected ILogger BaseLogger { get; set; } + /// + /// Makes the topic that loggers created on this execution context attach to. + /// + /// The topic to nest newly created loggers under. + /// A scope that restores the previously ambient topic when disposed. + internal static IDisposable BeginAmbientTopic(StartupLogTopic? topic) + { + var scope = new AmbientTopicScope(_ambientTopic.Value); + _ambientTopic.Value = topic; + return scope; + } + /// public IStartupLogger BeginGroup(FormattableString logEntry) { @@ -121,4 +137,19 @@ public class StartupLogger : IStartupLogger Topic.Children.Add(startupEntry); } } + + private sealed class AmbientTopicScope : IDisposable + { + private readonly StartupLogTopic? _previous; + + public AmbientTopicScope(StartupLogTopic? previous) + { + _previous = previous; + } + + public void Dispose() + { + _ambientTopic.Value = _previous; + } + } } -- cgit v1.2.3