This is an automated email from the ASF dual-hosted git repository.
freeandnil pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4net.git
The following commit(s) were added to refs/heads/master by this push:
new 0ee8ef93 Shutdown: Unsubscribe from AppDomain event handlers (#256)
0ee8ef93 is described below
commit 0ee8ef939b8eb598bd6a86b621e58a8a95800ffc
Author: Flo Lee <[email protected]>
AuthorDate: Mon Jun 16 14:23:09 2025 +0200
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.
---
src/log4net/Core/LoggerManager.cs | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/log4net/Core/LoggerManager.cs
b/src/log4net/Core/LoggerManager.cs
index 8b8084a7..8537e8c0 100644
--- a/src/log4net/Core/LoggerManager.cs
+++ b/src/log4net/Core/LoggerManager.cs
@@ -339,6 +339,10 @@ public static ILogger GetLogger(Assembly
repositoryAssembly, Type type)
/// </remarks>
public static void Shutdown()
{
+ //Cleanup event handlers since they only call this mathod anyways
+ AppDomain.CurrentDomain.ProcessExit -= OnProcessExit;
+ AppDomain.CurrentDomain.DomainUnload -= OnDomainUnload;
+
foreach (ILoggerRepository repository in GetAllRepositories())
{
repository.Shutdown();
@@ -572,4 +576,4 @@ private static string GetVersionInfo()
/// log message.
/// </remarks>
private static readonly Type _declaringType = typeof(LoggerManager);
-}
\ No newline at end of file
+}