Skip to content

Commit

Permalink
NLogAspNetCoreOptions - Enable ShutdownOnDispose by default (#691)
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot authored Aug 30, 2021
1 parent b5b5511 commit 9c42f97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/NLog.Web.AspNetCore/AspNetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,15 @@ private static NLogLoggerProvider CreateNLogLoggerProvider(IServiceProvider serv
NLogLoggerProvider provider = new NLogLoggerProvider(options ?? NLogAspNetCoreOptions.Default, logFactory ?? LogManager.LogFactory);
if (configuration != null)
{
if (options == null)
{
provider.Configure(configuration.GetSection("Logging:NLog"));
}

provider.Configure(configuration.GetSection("Logging:NLog"));
TryLoadConfigurationFromSection(provider, configuration);
}

if (provider.Options.ShutdownOnDispose)
{
provider.LogFactory.AutoShutdown = false;
}

return provider;
}

Expand Down
8 changes: 8 additions & 0 deletions src/NLog.Web.AspNetCore/NLogAspNetCoreOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,13 @@ public sealed class NLogAspNetCoreOptions : NLogProviderOptions
/// The default options
/// </summary>
public static NLogAspNetCoreOptions Default { get; } = new NLogAspNetCoreOptions();

/// <summary>
/// Initializes a new instance of <see cref="NLogAspNetCoreOptions"/> with default values.
/// </summary>
public NLogAspNetCoreOptions()
{
ShutdownOnDispose = true;
}
}
}

0 comments on commit 9c42f97

Please sign in to comment.