Skip to content

Commit df11d45

Browse files
committed
Version 5.3.9
1 parent 65d2adb commit df11d45

File tree

8 files changed

+57
-46
lines changed

8 files changed

+57
-46
lines changed

CHANGELOG.MD

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Date format: (year/month/day)
44

5+
### Version 5.3.9 (2024/04/27)
6+
**Improvements**
7+
- [#724](https://github.com/NLog/NLog.Extensions.Logging/pull/724): Skipping empty config sections without throwing exceptions (#724) (@RodionovDmitry)
8+
- [#737](https://github.com/NLog/NLog.Extensions.Logging/pull/737): Auto ordering of variables-section when dependent variables (#737) (@snakefoot)
9+
- [#741](https://github.com/NLog/NLog.Extensions.Logging/pull/741): Updated to NLog v5.3.0 (#741) (@snakefoot)
10+
511
### Version 5.3.8 (2023/12/29)
612

713
**Improvements**

build.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# creates NuGet package at \artifacts
33
dotnet --version
44

5-
$versionPrefix = "5.3.8"
5+
$versionPrefix = "5.3.9"
66
$versionSuffix = ""
77
$versionFile = $versionPrefix + "." + ${env:APPVEYOR_BUILD_NUMBER}
88
$versionProduct = $versionPrefix;

examples/NetCore2/HostingExample/HostingExample.csproj

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
8-
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
8+
99
<PublishTrimmed>true</PublishTrimmed>
10+
<PublishSingleFile>true</PublishSingleFile>
11+
<PublishReadyToRun>true</PublishReadyToRun>
12+
<SelfContained>true</SelfContained>
13+
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
14+
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
1015
</PropertyGroup>
1116

1217
<ItemGroup>

src/NLog.Extensions.Hosting/Extensions/ConfigureExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public static IHostBuilder UseNLog(this IHostBuilder builder, NLogProviderOption
4646

4747
private static void AddNLogLoggerProvider(IServiceCollection services, IConfiguration hostConfiguration, IHostEnvironment hostEnvironment, NLogProviderOptions options, Func<IServiceProvider, IConfiguration, IHostEnvironment, NLogProviderOptions, NLogLoggerProvider> factory)
4848
{
49-
LogManager.AddHiddenAssembly(typeof(ConfigureExtensions).GetTypeInfo().Assembly);
5049
services.TryAddNLogLoggingProvider((svc, addlogging) => svc.AddLogging(addlogging), hostConfiguration, options, (provider, cfg, opt) => factory(provider, cfg, hostEnvironment, opt));
5150
}
5251

@@ -60,6 +59,7 @@ private static NLogLoggerProvider CreateNLogLoggerProvider(IServiceProvider serv
6059
TryLoadConfigurationFromContentRootPath(provider.LogFactory, contentRootPath, hostEnvironment?.EnvironmentName);
6160
}
6261

62+
provider.LogFactory.Setup().SetupLogFactory(ext => ext.AddCallSiteHiddenAssembly(typeof(ConfigureExtensions).Assembly));
6363
return provider;
6464
}
6565

src/NLog.Extensions.Logging/Config/SetupExtensionsBuilderExtensions.cs

-36
Original file line numberDiff line numberDiff line change
@@ -16,47 +16,11 @@ public static class SetupExtensionsBuilderExtensions
1616
/// </summary>
1717
public static ISetupExtensionsBuilder RegisterConfigSettings(this ISetupExtensionsBuilder setupBuilder, IConfiguration configuration)
1818
{
19-
RegisterHiddenAssembliesForCallSite();
2019
ConfigSettingLayoutRenderer.DefaultConfiguration = configuration ?? ConfigSettingLayoutRenderer.DefaultConfiguration;
2120
return setupBuilder.RegisterLayoutRenderer<ConfigSettingLayoutRenderer>("configsetting")
2221
.RegisterLayoutRenderer<MicrosoftConsoleLayoutRenderer>("MicrosoftConsoleLayout")
2322
.RegisterLayout<MicrosoftConsoleJsonLayout>("MicrosoftConsoleJsonLayout")
2423
.RegisterTarget<MicrosoftILoggerTarget>("MicrosoftILogger");
2524
}
26-
27-
internal static void RegisterHiddenAssembliesForCallSite()
28-
{
29-
InternalLogger.Debug("Hide assemblies for callsite");
30-
LogManager.AddHiddenAssembly(typeof(NLogLoggerProvider).GetTypeInfo().Assembly);
31-
LogManager.AddHiddenAssembly(typeof(Microsoft.Extensions.Logging.ILogger).GetTypeInfo().Assembly);
32-
#if !NETCORE1_0
33-
LogManager.AddHiddenAssembly(typeof(Microsoft.Extensions.Logging.LoggerFactory).GetTypeInfo().Assembly);
34-
#else
35-
SafeAddHiddenAssembly("Microsoft.Logging");
36-
SafeAddHiddenAssembly("Microsoft.Extensions.Logging");
37-
38-
//try the Filter ext, this one is not mandatory so could fail
39-
SafeAddHiddenAssembly("Microsoft.Extensions.Logging.Filter", false);
40-
#endif
41-
}
42-
43-
#if NETCORE1_0
44-
private static void SafeAddHiddenAssembly(string assemblyName, bool logOnException = true)
45-
{
46-
try
47-
{
48-
InternalLogger.Trace("Hide {0}", assemblyName);
49-
var assembly = Assembly.Load(new AssemblyName(assemblyName));
50-
LogManager.AddHiddenAssembly(assembly);
51-
}
52-
catch (Exception ex)
53-
{
54-
if (logOnException)
55-
{
56-
InternalLogger.Debug(ex, "Hiding assembly {0} failed. This could influence the ${{callsite}}", assemblyName);
57-
}
58-
}
59-
}
60-
#endif
6125
}
6226
}

src/NLog.Extensions.Logging/Internal/RegisterNLogLoggingProvider.cs

+37-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System;
44
using System.Linq;
5+
using System.Reflection;
56
using Microsoft.Extensions.Configuration;
67
#if !NETCORE1_0
78
using Microsoft.Extensions.DependencyInjection;
@@ -91,8 +92,43 @@ internal static NLogLoggerProvider CreateNLogLoggerProvider(this IServiceProvide
9192
internal static IConfiguration SetupNLogConfigSettings(this IServiceProvider serviceProvider, IConfiguration configuration, LogFactory logFactory)
9293
{
9394
configuration = configuration ?? (serviceProvider?.GetService(typeof(IConfiguration)) as IConfiguration);
94-
logFactory.Setup().SetupExtensions(ext => ext.RegisterConfigSettings(configuration));
95+
logFactory.Setup()
96+
.SetupExtensions(ext => ext.RegisterConfigSettings(configuration))
97+
.SetupLogFactory(ext =>
98+
{
99+
ext.AddCallSiteHiddenAssembly(typeof(NLogLoggerProvider).GetTypeInfo().Assembly);
100+
ext.AddCallSiteHiddenAssembly(typeof(Microsoft.Extensions.Logging.ILogger).GetTypeInfo().Assembly);
101+
#if !NETCORE1_0
102+
ext.AddCallSiteHiddenAssembly(typeof(Microsoft.Extensions.Logging.LoggerFactory).GetTypeInfo().Assembly);
103+
#else
104+
var loggingAssembly = SafeLoadHiddenAssembly("Microsoft.Logging");
105+
ext.AddCallSiteHiddenAssembly(loggingAssembly ?? typeof(NLogLoggerProvider).GetTypeInfo().Assembly);
106+
var extensionAssembly = SafeLoadHiddenAssembly("Microsoft.Extensions.Logging");
107+
ext.AddCallSiteHiddenAssembly(extensionAssembly ?? typeof(NLogLoggerProvider).GetTypeInfo().Assembly);
108+
var filterAssembly = SafeLoadHiddenAssembly("Microsoft.Extensions.Logging.Filter", false);
109+
ext.AddCallSiteHiddenAssembly(filterAssembly ?? typeof(NLogLoggerProvider).GetTypeInfo().Assembly);
110+
#endif
111+
});
95112
return configuration;
96113
}
114+
115+
#if NETCORE1_0
116+
private static Assembly SafeLoadHiddenAssembly(string assemblyName, bool logOnException = true)
117+
{
118+
try
119+
{
120+
Common.InternalLogger.Debug("Loading Assembly {0} to mark it as hidden for callsite", assemblyName);
121+
return Assembly.Load(new AssemblyName(assemblyName));
122+
}
123+
catch (Exception ex)
124+
{
125+
if (logOnException)
126+
{
127+
Common.InternalLogger.Debug(ex, "Failed loading Loading Assembly {0} to mark it as hidden for callsite", assemblyName);
128+
}
129+
return null;
130+
}
131+
}
132+
#endif
97133
}
98134
}

src/NLog.Extensions.Logging/Logging/NLogLoggerFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public NLogLoggerFactory()
2929
public NLogLoggerFactory(NLogProviderOptions options)
3030
:this(new NLogLoggerProvider(options))
3131
{
32-
SetupExtensionsBuilderExtensions.RegisterHiddenAssembliesForCallSite();
32+
RegisterNLogLoggingProvider.SetupNLogConfigSettings(null, null, _provider.LogFactory);
3333
}
3434

3535
/// <summary>

src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ For ASP.NET Core, check: https://www.nuget.org/packages/NLog.Web.AspNetCore
1818
<PackageReleaseNotes>
1919
ChangeLog:
2020

21-
- Fixed IncludeActivityIdsWithBeginScope to work with NET 8.0 (#719) (@Owen-Krueger)
22-
- UseNLog includes EnvironmentName when loading NLog config (#714) (@snakefoot)
23-
- Updated to NLog v5.2.8 (#720) (@snakefoot)
21+
- Skipping empty config sections without throwing exceptions (#724) (@RodionovDmitry)
22+
- Auto ordering of variables-section when dependent variables (#737) (@snakefoot)
23+
- Updated to NLog v5.3.0 (#741) (@snakefoot)
2424

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

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

8585
<ItemGroup>
86-
<PackageReference Include="NLog" Version="5.2.8" />
86+
<PackageReference Include="NLog" Version="5.3.1" />
8787
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
8888
</ItemGroup>
8989
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">

0 commit comments

Comments
 (0)