FreeAndNil commented on code in PR #306: URL: https://github.com/apache/logging-log4net/pull/306#discussion_r3738301773
########## src/log4net/Config/XmlConfigurator.cs: ########## @@ -140,7 +140,7 @@ private static void InternalConfigure(ILoggerRepository repository, Func<XmlElem /// </remarks> /// <seealso cref="Log4NetConfigurationSectionHandler"/> public static ICollection Configure() - => Configure(LogManager.GetRepository(Assembly.GetCallingAssembly())); + => Configure(LogManager.GetRepository(CallerAssembly.IsSupported ? Assembly.GetCallingAssembly() : CallerAssembly.Fallback)); Review Comment: @fluffynuts Good catch, but this one can't move - though I don't like it either. `Assembly.GetCallingAssembly()` returns the caller of the method *containing* the call, so in a property on `CallerAssembly` the caller is log4net itself - every logger would land in log4net's own repository. Two-assembly harness, called from `UserApp`: ``` inline (current PR) -> UserApp <- correct via property (suggested) -> log4net ``` The lazy backing field is worse: the first assembly to touch it wins forever, so the result depends on load order. The BCL hits this exact problem and needs an internal enum for it - [`System.Threading.StackCrawlMark`](https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Threading/StackCrawlMark.cs) (`LookForMyCaller`, `LookForMyCallersCaller`), passed by `ref` so `Assembly.Load` can delegate to a private helper. It's `NotPublic` and no public API accepts it. It also wouldn't help us: it's stack-walking machinery, and AOT throws precisely because there is no stack to walk. Only a Roslyn [interceptor](https://github.com/dotnet/roslyn/blob/main/docs/features/interceptors.md) would actually remove the repetition - left out here, but I'm happy to open a separate issue. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
