diff --git a/NLog.Web.AspNetCore/AspNetExtensions.cs b/NLog.Web.AspNetCore/AspNetExtensions.cs
index 052999c8..6a6bcc39 100644
--- a/NLog.Web.AspNetCore/AspNetExtensions.cs
+++ b/NLog.Web.AspNetCore/AspNetExtensions.cs
@@ -60,9 +60,10 @@ 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)
{
+ ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly);
builder.AddNLog();
return LogManager.LoadConfiguration(configFileName);
}
@@ -75,9 +76,10 @@ 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)
{
+ 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
-
+