Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved registration of hidden assemblies for callsite handling #272

Merged
merged 3 commits into from
Apr 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 6 additions & 22 deletions NLog.Web.AspNetCore/AspNetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ public static LoggingConfiguration ConfigureNLog(this IHostingEnvironment env, s
/// <param name="builder">The logging builder</param>
/// <param name="configFileName">Path to NLog configuration file, e.g. nlog.config. </param>>
/// <returns>LogFactory to get loggers, add events etc</returns>
[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);
}
Expand All @@ -75,9 +76,10 @@ public static LogFactory ConfigureNLog(this ILoggingBuilder builder, string conf
/// <param name="builder">The logging builder</param>
/// <param name="configuration">Config for NLog</param>
/// <returns>LogFactory to get loggers, add events etc</returns>
[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;
Expand All @@ -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
Expand All @@ -116,29 +120,9 @@ public static IWebHostBuilder UseNLog(this IWebHostBuilder builder, NLogAspNetCo
{
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
}

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

}
Expand Down
2 changes: 1 addition & 1 deletion NLog.Web.AspNetCore/NLog.Web.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Recommend to replace `LogManager.LoadConfiguration` with `NLogBuilder.ConfigureN
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NLog.Extensions.Logging" Version="1.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.0.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
Expand Down