Skip to content

Commit

Permalink
Version 5.3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot committed Apr 27, 2024
1 parent 65d2adb commit df11d45
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 46 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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.0 (#741) (@snakefoot)

### Version 5.3.8 (2023/12/29)

**Improvements**
Expand Down
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions examples/NetCore2/HostingExample/HostingExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>

<PublishTrimmed>true</PublishTrimmed>
<PublishSingleFile>true</PublishSingleFile>
<PublishReadyToRun>true</PublishReadyToRun>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IServiceProvider, IConfiguration, IHostEnvironment, NLogProviderOptions, NLogLoggerProvider> factory)
{
LogManager.AddHiddenAssembly(typeof(ConfigureExtensions).GetTypeInfo().Assembly);
services.TryAddNLogLoggingProvider((svc, addlogging) => svc.AddLogging(addlogging), hostConfiguration, options, (provider, cfg, opt) => factory(provider, cfg, hostEnvironment, opt));
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,11 @@ public static class SetupExtensionsBuilderExtensions
/// </summary>
public static ISetupExtensionsBuilder RegisterConfigSettings(this ISetupExtensionsBuilder setupBuilder, IConfiguration configuration)
{
RegisterHiddenAssembliesForCallSite();
ConfigSettingLayoutRenderer.DefaultConfiguration = configuration ?? ConfigSettingLayoutRenderer.DefaultConfiguration;
return setupBuilder.RegisterLayoutRenderer<ConfigSettingLayoutRenderer>("configsetting")
.RegisterLayoutRenderer<MicrosoftConsoleLayoutRenderer>("MicrosoftConsoleLayout")
.RegisterLayout<MicrosoftConsoleJsonLayout>("MicrosoftConsoleJsonLayout")
.RegisterTarget<MicrosoftILoggerTarget>("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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.Configuration;
#if !NETCORE1_0
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion src/NLog.Extensions.Logging/Logging/NLogLoggerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public NLogLoggerFactory()
public NLogLoggerFactory(NLogProviderOptions options)
:this(new NLogLoggerProvider(options))
{
SetupExtensionsBuilderExtensions.RegisterHiddenAssembliesForCallSite();
RegisterNLogLoggingProvider.SetupNLogConfigSettings(null, null, _provider.LogFactory);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ For ASP.NET Core, check: https://www.nuget.org/packages/NLog.Web.AspNetCore
<PackageReleaseNotes>
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.0 (#741) (@snakefoot)

Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHANGELOG.MD

Expand Down Expand Up @@ -83,7 +83,7 @@ List of major changes in NLog 5.0: https://nlog-project.org/2021/08/25/nlog-5-0-
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="NLog" Version="5.3.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
Expand Down

0 comments on commit df11d45

Please sign in to comment.