From 4ae34e92e11f25873b73831e2737257c1e002807 Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Sat, 27 Apr 2024 12:08:12 +0200 Subject: [PATCH] Version 5.3.9 --- CHANGELOG.MD | 6 +++ build.ps1 | 2 +- .../HostingExample/HostingExample.csproj | 9 ++++- .../Extensions/ConfigureExtensions.cs | 2 +- .../SetupExtensionsBuilderExtensions.cs | 36 ------------------ .../Internal/RegisterNLogLoggingProvider.cs | 38 ++++++++++++++++++- .../Logging/NLogLoggerFactory.cs | 2 +- .../NLog.Extensions.Logging.csproj | 8 ++-- 8 files changed, 57 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index dbfe8804..b6c49570 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -2,6 +2,12 @@ Date format: (year/month/day) +### 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) +- [#741](https://github.com/NLog/NLog.Extensions.Logging/pull/741): Updated to NLog v5.3.1 (#741) (@snakefoot) + ### Version 5.3.8 (2023/12/29) **Improvements** diff --git a/build.ps1 b/build.ps1 index a55409a2..b328f488 100644 --- a/build.ps1 +++ b/build.ps1 @@ -2,7 +2,7 @@ # creates NuGet package at \artifacts dotnet --version -$versionPrefix = "5.3.8" +$versionPrefix = "5.3.9" $versionSuffix = "" $versionFile = $versionPrefix + "." + ${env:APPVEYOR_BUILD_NUMBER} $versionProduct = $versionPrefix; diff --git a/examples/NetCore2/HostingExample/HostingExample.csproj b/examples/NetCore2/HostingExample/HostingExample.csproj index f6deff79..0baf7fd4 100644 --- a/examples/NetCore2/HostingExample/HostingExample.csproj +++ b/examples/NetCore2/HostingExample/HostingExample.csproj @@ -2,11 +2,16 @@ Exe - net7.0 + net8.0 enable true - true + true + true + true + true + win-x64 + true diff --git a/src/NLog.Extensions.Hosting/Extensions/ConfigureExtensions.cs b/src/NLog.Extensions.Hosting/Extensions/ConfigureExtensions.cs index 44e4a2b0..002bf02e 100644 --- a/src/NLog.Extensions.Hosting/Extensions/ConfigureExtensions.cs +++ b/src/NLog.Extensions.Hosting/Extensions/ConfigureExtensions.cs @@ -46,7 +46,6 @@ public static IHostBuilder UseNLog(this IHostBuilder builder, NLogProviderOption private static void AddNLogLoggerProvider(IServiceCollection services, IConfiguration hostConfiguration, IHostEnvironment hostEnvironment, NLogProviderOptions options, Func factory) { - LogManager.AddHiddenAssembly(typeof(ConfigureExtensions).GetTypeInfo().Assembly); services.TryAddNLogLoggingProvider((svc, addlogging) => svc.AddLogging(addlogging), hostConfiguration, options, (provider, cfg, opt) => factory(provider, cfg, hostEnvironment, opt)); } @@ -60,6 +59,7 @@ private static NLogLoggerProvider CreateNLogLoggerProvider(IServiceProvider serv TryLoadConfigurationFromContentRootPath(provider.LogFactory, contentRootPath, hostEnvironment?.EnvironmentName); } + provider.LogFactory.Setup().SetupLogFactory(ext => ext.AddCallSiteHiddenAssembly(typeof(ConfigureExtensions).Assembly)); return provider; } diff --git a/src/NLog.Extensions.Logging/Config/SetupExtensionsBuilderExtensions.cs b/src/NLog.Extensions.Logging/Config/SetupExtensionsBuilderExtensions.cs index 74862e48..b667eb05 100644 --- a/src/NLog.Extensions.Logging/Config/SetupExtensionsBuilderExtensions.cs +++ b/src/NLog.Extensions.Logging/Config/SetupExtensionsBuilderExtensions.cs @@ -16,47 +16,11 @@ public static class SetupExtensionsBuilderExtensions /// public static ISetupExtensionsBuilder RegisterConfigSettings(this ISetupExtensionsBuilder setupBuilder, IConfiguration configuration) { - RegisterHiddenAssembliesForCallSite(); ConfigSettingLayoutRenderer.DefaultConfiguration = configuration ?? ConfigSettingLayoutRenderer.DefaultConfiguration; return setupBuilder.RegisterLayoutRenderer("configsetting") .RegisterLayoutRenderer("MicrosoftConsoleLayout") .RegisterLayout("MicrosoftConsoleJsonLayout") .RegisterTarget("MicrosoftILogger"); } - - internal static void RegisterHiddenAssembliesForCallSite() - { - InternalLogger.Debug("Hide assemblies for callsite"); - LogManager.AddHiddenAssembly(typeof(NLogLoggerProvider).GetTypeInfo().Assembly); - LogManager.AddHiddenAssembly(typeof(Microsoft.Extensions.Logging.ILogger).GetTypeInfo().Assembly); -#if !NETCORE1_0 - LogManager.AddHiddenAssembly(typeof(Microsoft.Extensions.Logging.LoggerFactory).GetTypeInfo().Assembly); -#else - SafeAddHiddenAssembly("Microsoft.Logging"); - SafeAddHiddenAssembly("Microsoft.Extensions.Logging"); - - //try the Filter ext, this one is not mandatory so could fail - SafeAddHiddenAssembly("Microsoft.Extensions.Logging.Filter", false); -#endif - } - -#if NETCORE1_0 - private static void SafeAddHiddenAssembly(string assemblyName, bool logOnException = true) - { - try - { - InternalLogger.Trace("Hide {0}", assemblyName); - var assembly = Assembly.Load(new AssemblyName(assemblyName)); - LogManager.AddHiddenAssembly(assembly); - } - catch (Exception ex) - { - if (logOnException) - { - InternalLogger.Debug(ex, "Hiding assembly {0} failed. This could influence the ${{callsite}}", assemblyName); - } - } - } -#endif } } diff --git a/src/NLog.Extensions.Logging/Internal/RegisterNLogLoggingProvider.cs b/src/NLog.Extensions.Logging/Internal/RegisterNLogLoggingProvider.cs index 317992d1..acd32333 100644 --- a/src/NLog.Extensions.Logging/Internal/RegisterNLogLoggingProvider.cs +++ b/src/NLog.Extensions.Logging/Internal/RegisterNLogLoggingProvider.cs @@ -2,6 +2,7 @@ { using System; using System.Linq; + using System.Reflection; using Microsoft.Extensions.Configuration; #if !NETCORE1_0 using Microsoft.Extensions.DependencyInjection; @@ -91,8 +92,43 @@ 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)); + 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 + }); 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/Logging/NLogLoggerFactory.cs b/src/NLog.Extensions.Logging/Logging/NLogLoggerFactory.cs index a9400ed3..8945b24c 100644 --- a/src/NLog.Extensions.Logging/Logging/NLogLoggerFactory.cs +++ b/src/NLog.Extensions.Logging/Logging/NLogLoggerFactory.cs @@ -29,7 +29,7 @@ public NLogLoggerFactory() public NLogLoggerFactory(NLogProviderOptions options) :this(new NLogLoggerProvider(options)) { - SetupExtensionsBuilderExtensions.RegisterHiddenAssembliesForCallSite(); + RegisterNLogLoggingProvider.SetupNLogConfigSettings(null, null, _provider.LogFactory); } /// diff --git a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj index 524dbd9a..48d96052 100644 --- a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj +++ b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj @@ -18,9 +18,9 @@ For ASP.NET Core, check: https://www.nuget.org/packages/NLog.Web.AspNetCore ChangeLog: -- Fixed IncludeActivityIdsWithBeginScope to work with NET 8.0 (#719) (@Owen-Krueger) -- UseNLog includes EnvironmentName when loading NLog config (#714) (@snakefoot) -- Updated to NLog v5.2.8 (#720) (@snakefoot) +- Skipping empty config sections without throwing exceptions (#724) (@RodionovDmitry) +- Auto ordering of variables-section when dependent variables (#737) (@snakefoot) +- Updated to NLog v5.3.1 (#741) (@snakefoot) Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHANGELOG.MD @@ -83,7 +83,7 @@ List of major changes in NLog 5.0: https://nlog-project.org/2021/08/25/nlog-5-0- - +