Skip to content

Commit 0ee8ef9

Browse files
authored
Shutdown: Unsubscribe from AppDomain event handlers (#256)
* Shutdown: Unsubscribe from AppDomain event handlers When log4net is used in an AssemblyLoadContext that should be unloaded, log4net blocks the unloading since it subscribed to event handlers from the default load context. This PR aims to cleanup the 2 subscriptions that most likely cause this behaviour. Note that I did not fully test the solution yet. But this cleanup is a good measure in any case.
1 parent 6e9f2d5 commit 0ee8ef9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/log4net/Core/LoggerManager.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ public static ILogger GetLogger(Assembly repositoryAssembly, Type type)
339339
/// </remarks>
340340
public static void Shutdown()
341341
{
342+
//Cleanup event handlers since they only call this mathod anyways
343+
AppDomain.CurrentDomain.ProcessExit -= OnProcessExit;
344+
AppDomain.CurrentDomain.DomainUnload -= OnDomainUnload;
345+
342346
foreach (ILoggerRepository repository in GetAllRepositories())
343347
{
344348
repository.Shutdown();
@@ -572,4 +576,4 @@ private static string GetVersionInfo()
572576
/// log message.
573577
/// </remarks>
574578
private static readonly Type _declaringType = typeof(LoggerManager);
575-
}
579+
}

0 commit comments

Comments
 (0)