Skip to content

Commit

Permalink
Reverted NLog#410 and instead introduced LoadNLogConfigFromSection on…
Browse files Browse the repository at this point in the history
… ISetupBuilder
  • Loading branch information
snakefoot committed Mar 31, 2020
1 parent 8787454 commit f340c95
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 56 deletions.
13 changes: 0 additions & 13 deletions src/NLog.Extensions.Logging/Config/ISetupLoggerProviderBuilder.cs

This file was deleted.

21 changes: 8 additions & 13 deletions src/NLog.Extensions.Logging/Config/SetupBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System.Linq;
using NLog.Config;

namespace NLog.Extensions.Logging
Expand All @@ -9,22 +9,17 @@ namespace NLog.Extensions.Logging
public static class SetupBuilderExtensions
{
/// <summary>
/// Setup of LogFactory integration with Microsoft Extension Logging
/// Loads NLog LoggingConfiguration from appsettings.json from NLog-section
/// </summary>
public static ISetupBuilder SetupExtensionLogging(this ISetupBuilder setupBuilder, Action<ISetupExtensionLoggingBuilder> extensionsBuilder)
public static ISetupBuilder LoadNLogConfigFromSection(this ISetupBuilder setupBuilder, Microsoft.Extensions.Configuration.IConfiguration configuration)
{
extensionsBuilder(new SetupExtensionLoggingBuilder(setupBuilder.LogFactory));
return setupBuilder;
}

private class SetupExtensionLoggingBuilder : ISetupExtensionLoggingBuilder
{
public SetupExtensionLoggingBuilder(LogFactory logFactory)
setupBuilder.SetupExtensions(s => s.RegisterConfigSettings(configuration));
var nlogConfig = configuration.GetSection("NLog");
if (nlogConfig != null && nlogConfig.GetChildren().Any())
{
LogFactory = logFactory;
setupBuilder.LogFactory.Configuration = new NLogLoggingConfiguration(nlogConfig, setupBuilder.LogFactory);
}

public LogFactory LogFactory { get; }
return setupBuilder;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.Extensions.Configuration;
using NLog.Config;

namespace NLog.Extensions.Logging
{
/// <summary>
/// Extension methods to setup NLog extensions, so they are known when loading NLog LoggingConfiguration
/// </summary>
public static class SetupExtensionsBuilderExtensions
{
/// <summary>
/// Replace with version from NLog.Extension.Logging when it has been released with NLog 4.7
/// </summary>
internal static ISetupExtensionsBuilder RegisterConfigSettings(this ISetupExtensionsBuilder setupBuilder, IConfiguration configuration)
{
ConfigSettingLayoutRenderer.DefaultConfiguration = configuration;
ConfigurationItemFactory.Default.RegisterType(typeof(ConfigSettingLayoutRenderer), string.Empty);
return setupBuilder;
}
}
}

This file was deleted.

0 comments on commit f340c95

Please sign in to comment.