diff --git a/CHANGELOG.MD b/CHANGELOG.MD index c4e92563..5ffc648f 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -2,12 +2,19 @@ Date format: (year/month/day) +### Version 5.3.11 (2024/05/07) + +**Improvements** +- [#745](https://github.com/NLog/NLog.Extensions.Logging/pull/745): Fixed CallSite-logic for NLog.Web.AspNetCore (#745) (@snakefoot) + ### Version 5.3.10 (2024/04/30) + **Improvements** - [#742](https://github.com/NLog/NLog.Extensions.Logging/pull/742): Improve auto ordering of variables-section when dependent variables (#742) (@snakefoot) - [#743](https://github.com/NLog/NLog.Extensions.Logging/pull/743): Updated to NLog v5.3.2 (#743) (@snakefoot) ### Version 5.3.9 (2024/04/27) + **Improvements** - [#724](https://github.com/NLog/NLog.Extensions.Logging/pull/724): Skipping empty config sections without throwing exceptions (#724) (@RodionovDmitry) - [#737](https://github.com/NLog/NLog.Extensions.Logging/pull/737): Auto ordering of variables-section when dependent variables (#737) (@snakefoot) diff --git a/build.ps1 b/build.ps1 index 5b3d767a..400bdaac 100644 --- a/build.ps1 +++ b/build.ps1 @@ -2,7 +2,7 @@ # creates NuGet package at \artifacts dotnet --version -$versionPrefix = "5.3.10" +$versionPrefix = "5.3.11" $versionSuffix = "" $versionFile = $versionPrefix + "." + ${env:APPVEYOR_BUILD_NUMBER} $versionProduct = $versionPrefix; diff --git a/src/NLog.Extensions.Logging/Config/SetupExtensionsBuilderExtensions.cs b/src/NLog.Extensions.Logging/Config/SetupExtensionsBuilderExtensions.cs index b667eb05..ae0fb6fd 100644 --- a/src/NLog.Extensions.Logging/Config/SetupExtensionsBuilderExtensions.cs +++ b/src/NLog.Extensions.Logging/Config/SetupExtensionsBuilderExtensions.cs @@ -17,10 +17,44 @@ public static class SetupExtensionsBuilderExtensions public static ISetupExtensionsBuilder RegisterConfigSettings(this ISetupExtensionsBuilder setupBuilder, IConfiguration configuration) { ConfigSettingLayoutRenderer.DefaultConfiguration = configuration ?? ConfigSettingLayoutRenderer.DefaultConfiguration; + setupBuilder.LogFactory.Setup().SetupLogFactory(ext => + { + ext.AddCallSiteHiddenAssembly(typeof(NLogLoggerProvider).GetTypeInfo().Assembly); + ext.AddCallSiteHiddenAssembly(typeof(Microsoft.Extensions.Logging.ILogger).GetTypeInfo().Assembly); +#if !NETCORE1_0 + ext.AddCallSiteHiddenAssembly(typeof(Microsoft.Extensions.Logging.LoggerFactory).GetTypeInfo().Assembly); +#else + var loggingAssembly = SafeLoadHiddenAssembly("Microsoft.Logging"); + ext.AddCallSiteHiddenAssembly(loggingAssembly ?? typeof(NLogLoggerProvider).GetTypeInfo().Assembly); + var extensionAssembly = SafeLoadHiddenAssembly("Microsoft.Extensions.Logging"); + ext.AddCallSiteHiddenAssembly(extensionAssembly ?? typeof(NLogLoggerProvider).GetTypeInfo().Assembly); + var filterAssembly = SafeLoadHiddenAssembly("Microsoft.Extensions.Logging.Filter", false); + ext.AddCallSiteHiddenAssembly(filterAssembly ?? typeof(NLogLoggerProvider).GetTypeInfo().Assembly); +#endif + }); return setupBuilder.RegisterLayoutRenderer("configsetting") .RegisterLayoutRenderer("MicrosoftConsoleLayout") .RegisterLayout("MicrosoftConsoleJsonLayout") .RegisterTarget("MicrosoftILogger"); } + +#if NETCORE1_0 + private static Assembly SafeLoadHiddenAssembly(string assemblyName, bool logOnException = true) + { + try + { + InternalLogger.Debug("Loading Assembly {0} to mark it as hidden for callsite", assemblyName); + return Assembly.Load(new AssemblyName(assemblyName)); + } + catch (Exception ex) + { + if (logOnException) + { + InternalLogger.Debug(ex, "Failed loading Loading Assembly {0} to mark it as hidden for callsite", assemblyName); + } + return null; + } + } +#endif } } diff --git a/src/NLog.Extensions.Logging/Internal/RegisterNLogLoggingProvider.cs b/src/NLog.Extensions.Logging/Internal/RegisterNLogLoggingProvider.cs index acd32333..510df49f 100644 --- a/src/NLog.Extensions.Logging/Internal/RegisterNLogLoggingProvider.cs +++ b/src/NLog.Extensions.Logging/Internal/RegisterNLogLoggingProvider.cs @@ -92,43 +92,8 @@ internal static NLogLoggerProvider CreateNLogLoggerProvider(this IServiceProvide internal static IConfiguration SetupNLogConfigSettings(this IServiceProvider serviceProvider, IConfiguration configuration, LogFactory logFactory) { configuration = configuration ?? (serviceProvider?.GetService(typeof(IConfiguration)) as IConfiguration); - logFactory.Setup() - .SetupExtensions(ext => ext.RegisterConfigSettings(configuration)) - .SetupLogFactory(ext => - { - ext.AddCallSiteHiddenAssembly(typeof(NLogLoggerProvider).GetTypeInfo().Assembly); - ext.AddCallSiteHiddenAssembly(typeof(Microsoft.Extensions.Logging.ILogger).GetTypeInfo().Assembly); -#if !NETCORE1_0 - ext.AddCallSiteHiddenAssembly(typeof(Microsoft.Extensions.Logging.LoggerFactory).GetTypeInfo().Assembly); -#else - var loggingAssembly = SafeLoadHiddenAssembly("Microsoft.Logging"); - ext.AddCallSiteHiddenAssembly(loggingAssembly ?? typeof(NLogLoggerProvider).GetTypeInfo().Assembly); - var extensionAssembly = SafeLoadHiddenAssembly("Microsoft.Extensions.Logging"); - ext.AddCallSiteHiddenAssembly(extensionAssembly ?? typeof(NLogLoggerProvider).GetTypeInfo().Assembly); - var filterAssembly = SafeLoadHiddenAssembly("Microsoft.Extensions.Logging.Filter", false); - ext.AddCallSiteHiddenAssembly(filterAssembly ?? typeof(NLogLoggerProvider).GetTypeInfo().Assembly); -#endif - }); + logFactory.Setup().SetupExtensions(ext => ext.RegisterConfigSettings(configuration)); return configuration; } - -#if NETCORE1_0 - private static Assembly SafeLoadHiddenAssembly(string assemblyName, bool logOnException = true) - { - try - { - Common.InternalLogger.Debug("Loading Assembly {0} to mark it as hidden for callsite", assemblyName); - return Assembly.Load(new AssemblyName(assemblyName)); - } - catch (Exception ex) - { - if (logOnException) - { - Common.InternalLogger.Debug(ex, "Failed loading Loading Assembly {0} to mark it as hidden for callsite", assemblyName); - } - return null; - } - } -#endif } } diff --git a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj index 88e2db17..9d472f1a 100644 --- a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj +++ b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj @@ -18,8 +18,7 @@ For ASP.NET Core, check: https://www.nuget.org/packages/NLog.Web.AspNetCore ChangeLog: -- Improve auto ordering of variables-section when dependent variables (#742) (@snakefoot) -- Updated to NLog v5.3.2 (#743) (@snakefoot) +- Fixed CallSite-Logic for NLog.Web.AspNetCore (#745) (@snakefoot) Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHANGELOG.MD