From 78bbf5477dac696eedb9f26a4df8543655827e36 Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Fri, 6 Apr 2018 20:15:28 +0200 Subject: [PATCH 1/2] NLogBuilder is needed, because DLL autoload doesn't work unless the DLL has been loaded (Fix obsolete messages) --- NLog.Web.AspNetCore/AspNetExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NLog.Web.AspNetCore/AspNetExtensions.cs b/NLog.Web.AspNetCore/AspNetExtensions.cs index 052999c8..96348e23 100644 --- a/NLog.Web.AspNetCore/AspNetExtensions.cs +++ b/NLog.Web.AspNetCore/AspNetExtensions.cs @@ -60,7 +60,7 @@ public static LoggingConfiguration ConfigureNLog(this IHostingEnvironment env, s /// The logging builder /// Path to NLog configuration file, e.g. nlog.config. > /// LogFactory to get loggers, add events etc - [Obsolete("Use UseNLog() on IWebHostBuilder, and NLog.LogManager.LoadConfiguration()")] + [Obsolete("Use UseNLog() on IWebHostBuilder, and NLog.Web.NLogBuilder.ConfigureNLog()")] public static LogFactory ConfigureNLog(this ILoggingBuilder builder, string configFileName) { builder.AddNLog(); @@ -75,7 +75,7 @@ public static LogFactory ConfigureNLog(this ILoggingBuilder builder, string conf /// The logging builder /// Config for NLog /// LogFactory to get loggers, add events etc - [Obsolete("Use UseNLog() on IWebHostBuilder, and assign property NLog.LogManager.Configuration")] + [Obsolete("Use UseNLog() on IWebHostBuilder, and NLog.Web.NLogBuilder.ConfigureNLog()")] public static LogFactory ConfigureNLog(this ILoggingBuilder builder, LoggingConfiguration configuration) { builder.AddNLog(); From 6e82cd5c0169658ae6cdb137c93b5df20404a7e0 Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Sat, 7 Apr 2018 02:30:53 +0200 Subject: [PATCH 2/2] Removed RegisterHiddenAssembliesForCallSite as it is now handled by NLog.Extensions.Logging --- NLog.Web.AspNetCore/AspNetExtensions.cs | 24 ++++--------------- .../NLog.Web.AspNetCore.csproj | 2 +- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/NLog.Web.AspNetCore/AspNetExtensions.cs b/NLog.Web.AspNetCore/AspNetExtensions.cs index 96348e23..6a6bcc39 100644 --- a/NLog.Web.AspNetCore/AspNetExtensions.cs +++ b/NLog.Web.AspNetCore/AspNetExtensions.cs @@ -63,6 +63,7 @@ public static LoggingConfiguration ConfigureNLog(this IHostingEnvironment env, s [Obsolete("Use UseNLog() on IWebHostBuilder, and NLog.Web.NLogBuilder.ConfigureNLog()")] public static LogFactory ConfigureNLog(this ILoggingBuilder builder, string configFileName) { + ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly); builder.AddNLog(); return LogManager.LoadConfiguration(configFileName); } @@ -78,6 +79,7 @@ public static LogFactory ConfigureNLog(this ILoggingBuilder builder, string conf [Obsolete("Use UseNLog() on IWebHostBuilder, and NLog.Web.NLogBuilder.ConfigureNLog()")] public static LogFactory ConfigureNLog(this ILoggingBuilder builder, LoggingConfiguration configuration) { + ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly); builder.AddNLog(); LogManager.Configuration = configuration; return LogManager.LogFactory; @@ -102,6 +104,8 @@ public static IWebHostBuilder UseNLog(this IWebHostBuilder builder, NLogAspNetCo if (builder == null) throw new ArgumentNullException(nameof(builder)); options = options ?? NLogAspNetCoreOptions.Default; + ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly); + builder.ConfigureServices(services => { //note: when registering ILoggerFactory, all non NLog stuff and stuff before this will be removed @@ -116,29 +120,9 @@ public static IWebHostBuilder UseNLog(this IWebHostBuilder builder, NLogAspNetCo { services.TryAddSingleton(); } - - RegisterHiddenAssembliesForCallSite(); }); return builder; } - - private static void RegisterHiddenAssembliesForCallSite() - { - var allAssemblies = AppDomain.CurrentDomain.GetAssemblies(); - foreach (var assembly in allAssemblies) - { - if ( assembly.FullName.StartsWith("NLog.Extensions.Logging,", StringComparison.OrdinalIgnoreCase) - || assembly.FullName.StartsWith("NLog.Web,", StringComparison.OrdinalIgnoreCase) - || assembly.FullName.StartsWith("NLog.Web.AspNetCore,", StringComparison.OrdinalIgnoreCase) - || assembly.FullName.StartsWith("Microsoft.Extensions.Logging,", StringComparison.OrdinalIgnoreCase) - || assembly.FullName.StartsWith("Microsoft.Extensions.Logging.Abstractions,", StringComparison.OrdinalIgnoreCase) - || assembly.FullName.StartsWith("Microsoft.Extensions.Logging.Filter,", StringComparison.OrdinalIgnoreCase) - || assembly.FullName.StartsWith("Microsoft.Logging,", StringComparison.OrdinalIgnoreCase)) - { - LogManager.AddHiddenAssembly(assembly); - } - } - } #endif } diff --git a/NLog.Web.AspNetCore/NLog.Web.AspNetCore.csproj b/NLog.Web.AspNetCore/NLog.Web.AspNetCore.csproj index 4db4f0df..69481cb4 100644 --- a/NLog.Web.AspNetCore/NLog.Web.AspNetCore.csproj +++ b/NLog.Web.AspNetCore/NLog.Web.AspNetCore.csproj @@ -75,7 +75,7 @@ Recommend to replace `LogManager.LoadConfiguration` with `NLogBuilder.ConfigureN - +