Skip to content

Commit

Permalink
Merge pull request #322 from snakefoot/NLogLoggingConfigurationLeak
Browse files Browse the repository at this point in the history
NLogLoggingConfiguration - Fix leak in RegisterChangeCallback
  • Loading branch information
304NotModified authored Aug 28, 2019
2 parents 407e66f + 2888ab4 commit d617f90
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Date format: (year/month/day)

### v1.5.3 (2019/08/28)
- [#322](https://github.com/NLog/NLog.Extensions.Logging/pull/322) Fixed memory leak in NLogLoggingConfiguration for autoreload

### v1.5.2 (2019/07/14)
- [#314](https://github.com/NLog/NLog.Extensions.Logging/pull/314) Added NLogProviderOptions.ShutdownOnDispose (#314) (@304NotModified)
- [#315](https://github.com/NLog/NLog.Extensions.Logging/pull/315) Update NLog to 4.6.5 (#315) (@304NotModified)
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 = "1.5.2"
$versionPrefix = "1.5.3"
$versionSuffix = ""
$versionFile = $versionPrefix + "." + ${env:APPVEYOR_BUILD_NUMBER}
$versionProduct = $versionPrefix;
Expand Down
6 changes: 4 additions & 2 deletions src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@

<Company>NLog</Company>
<Authors>Julian Verdurmen;Bryan Gonzalez</Authors>
<Description>NLog extension for Microsoft.Extensions.Hosting for usage in .NET Standard libraries and net core applications making use of the generic Host class introduced in netcore 2.1</Description>
<Description>NLog extension for Microsoft.Extensions.Hosting for logging in .NET Standard libraries and .NET Core applications using IHostBuilder.

For ASP.NET Core, use NLog.Web.AspNetCore: https://www.nuget.org/packages/NLog.Web.AspNetCore </Description>
<PackageProjectUrl>https://github.com/NLog/NLog.Extensions.Logging</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/NLog/NLog.Extensions.Logging/blob/master/LICENSE</PackageLicenseUrl>
<PackageIconUrl>https://nlog-project.org/NConfig.png</PackageIconUrl>
<RepositoryUrl>https://github.com/NLog/NLog.Extensions.Logging.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>NLog;Microsoft.Extensions.Hosting;log;logfiles;netcore</PackageTags>
<PackageTags>NLog;Microsoft.Extensions.Hosting;log;logging;logfiles;netcore</PackageTags>
<PackageReleaseNotes>
Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHANGELOG.MD
</PackageReleaseNotes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class NLogLoggingConfiguration : LoggingConfigurationParser
private readonly IConfigurationSection _originalConfigSection;
private bool _autoReload;
private Action<object> _reloadConfiguration;
private IDisposable _registerChangeCallback;

/// <summary>
/// Initializes a new instance of the <see cref="NLogLoggingConfiguration" /> class.
Expand Down Expand Up @@ -76,6 +77,8 @@ private void LogFactory_ConfigurationChanged(object sender, LoggingConfiguration
{
_autoReload = false; // Cannot unsubscribe to reload event, but we can stop reacting to it
LogFactory.ConfigurationChanged -= LogFactory_ConfigurationChanged;
_registerChangeCallback?.Dispose();
_registerChangeCallback = null;
}
}
else if (ReferenceEquals(e.ActivatedConfiguration, this) && _autoReload && _reloadConfiguration != null)
Expand Down Expand Up @@ -117,7 +120,9 @@ private void ReloadConfigurationSection(IConfigurationSection nlogConfig)

private void MonitorForReload(IConfigurationSection nlogConfig)
{
nlogConfig.GetReloadToken().RegisterChangeCallback(_reloadConfiguration, nlogConfig);
_registerChangeCallback?.Dispose();
_registerChangeCallback = null;
_registerChangeCallback = nlogConfig.GetReloadToken().RegisterChangeCallback(_reloadConfiguration, nlogConfig);
}

private class LoggingConfigurationElement : ILoggingConfigurationElement
Expand Down Expand Up @@ -191,7 +196,6 @@ private IEnumerable<ILoggingConfigurationElement> GetChildren()
}

var isTargetsSection = IsTargetsSection();

if (isTargetsSection)
{
foreach (var targetDefaultConfig in GetTargetsDefaultConfigElements())
Expand Down
8 changes: 3 additions & 5 deletions src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@

<Authors>Microsoft;Julian Verdurmen</Authors>
<Company>NLog</Company>
<Description>NLog provider for Microsoft.Extensions.Logging for usage in .NET Standard libraries and console applicaties.
<Description>NLog LoggerProvider for Microsoft.Extensions.Logging for logging in .NET Standard libraries and .NET Core applications.

For ASP.NET Core, use NLog.Web.AspNetCore: https://www.nuget.org/packages/NLog.Web.AspNetCore
</Description>
<PackageTags>NLog;Microsoft.Extensions.Logging;log;logfiles;netcore</PackageTags>
<PackageTags>NLog;Microsoft.Extensions.Logging;log;logging;logfiles;netcore</PackageTags>
<PackageReleaseNotes>

- Added NLogProviderOptions.ShutdownOnDispose (#314) (@304NotModified)
- Update NLog to 4.6.5 (#315) (@304NotModified)
- Fixed memory leak in NLogLoggingConfiguration for autoreload #322 (@snakefoot)

Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHANGELOG.MD
</PackageReleaseNotes>
Expand Down

0 comments on commit d617f90

Please sign in to comment.