aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/ServerSetupApp
diff options
context:
space:
mode:
authorCody Robibero <cody@robibe.ro>2026-09-06 07:45:43 -0400
committerGitHub <noreply@github.com>2026-09-06 07:45:43 -0400
commitf898c35b9668318c1200bc6bc1659ffed47ee798 (patch)
treea2a7edcc97bf5668f948c1a495e93a55718887c9 /Jellyfin.Server/ServerSetupApp
parentbbb3a4896395978f8268cd9b32c8d8ca7ba2c15b (diff)
parentedb6cd11da0c3772ff897757a8364b309e6f7e1a (diff)
Merge pull request #17791 from Shadowghost/fix-code-migration
Don't dispose application singletons after running a code migration
Diffstat (limited to 'Jellyfin.Server/ServerSetupApp')
-rw-r--r--Jellyfin.Server/ServerSetupApp/StartupLogger.cs31
1 files changed, 31 insertions, 0 deletions
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;
/// <inheritdoc/>
public class StartupLogger : IStartupLogger
{
+ private static readonly AsyncLocal<StartupLogTopic?> _ambientTopic = new();
+
private readonly StartupLogTopic? _topic;
/// <summary>
@@ -17,6 +20,7 @@ public class StartupLogger : IStartupLogger
public StartupLogger(ILogger logger)
{
BaseLogger = logger;
+ _topic = _ambientTopic.Value;
}
/// <summary>
@@ -39,6 +43,18 @@ public class StartupLogger : IStartupLogger
/// </summary>
protected ILogger BaseLogger { get; set; }
+ /// <summary>
+ /// Makes <paramref name="topic"/> the topic that loggers created on this execution context attach to.
+ /// </summary>
+ /// <param name="topic">The topic to nest newly created loggers under.</param>
+ /// <returns>A scope that restores the previously ambient topic when disposed.</returns>
+ internal static IDisposable BeginAmbientTopic(StartupLogTopic? topic)
+ {
+ var scope = new AmbientTopicScope(_ambientTopic.Value);
+ _ambientTopic.Value = topic;
+ return scope;
+ }
+
/// <inheritdoc/>
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;
+ }
+ }
}