Skip to content

Commit

Permalink
Introduced AddNLogWeb to avoid conflict with AddNLog from NLog.Extens…
Browse files Browse the repository at this point in the history
…ion.Logging (#602)
  • Loading branch information
snakefoot authored Sep 26, 2020
1 parent f88eaa0 commit 8e2823a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 12 deletions.
67 changes: 66 additions & 1 deletion src/NLog.Web.AspNetCore/AspNetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,45 @@ public static LogFactory ConfigureNLog(this ILoggingBuilder builder, LoggingConf
return LogManager.LogFactory;
}

/// <summary>
/// Enable NLog as logging provider for Microsoft Extension Logging
/// </summary>
/// <param name="builder">The logging builder</param>
public static ILoggingBuilder AddNLogWeb(this ILoggingBuilder builder)
{
return builder.AddNLogWeb(NLogAspNetCoreOptions.Default);
}

/// <summary>
/// Enable NLog as logging provider for Microsoft Extension Logging
/// </summary>
/// <param name="builder">The logging builder</param>
/// <param name="options">Options for logging to NLog with Dependency Injected loggers</param>
public static ILoggingBuilder AddNLogWeb(this ILoggingBuilder builder, NLogAspNetCoreOptions options)
{
AddNLogLoggerProvider(builder.Services, null, options, (serviceProvider, config, opt) =>
{
return CreateNLogLoggerProvider(serviceProvider, config, opt);
});
return builder;
}

/// <summary>
/// Apply NLog configuration from XML config.
/// </summary>
/// <param name="builder">The logging builder</param>
/// <param name="configFileName">Path to NLog configuration file, e.g. nlog.config. </param>
public static ILoggingBuilder AddNLog(this ILoggingBuilder builder, string configFileName)
{
return AddNLogWeb(builder, configFileName);
}

/// <summary>
/// Apply NLog configuration from XML config.
/// </summary>
/// <param name="builder">The logging builder</param>
/// <param name="configFileName">Path to NLog configuration file, e.g. nlog.config. </param>
public static ILoggingBuilder AddNLogWeb(this ILoggingBuilder builder, string configFileName)
{
AddNLogLoggerProvider(builder.Services, null, null, (serviceProvider, config, options) =>
{
Expand All @@ -134,7 +167,17 @@ public static ILoggingBuilder AddNLog(this ILoggingBuilder builder, string confi
/// <param name="configuration">Config for NLog</param>
public static ILoggingBuilder AddNLog(this ILoggingBuilder builder, LoggingConfiguration configuration)
{
return AddNLog(builder, configuration, null);
return AddNLogWeb(builder, configuration);
}

/// <summary>
/// Configure NLog from API
/// </summary>
/// <param name="builder">The logging builder</param>
/// <param name="configuration">Config for NLog</param>
public static ILoggingBuilder AddNLogWeb(this ILoggingBuilder builder, LoggingConfiguration configuration)
{
return AddNLogWeb(builder, configuration, null);
}

/// <summary>
Expand All @@ -144,6 +187,17 @@ public static ILoggingBuilder AddNLog(this ILoggingBuilder builder, LoggingConfi
/// <param name="configuration">Config for NLog</param>
/// <param name="options">Options for logging to NLog with Dependency Injected loggers</param>
public static ILoggingBuilder AddNLog(this ILoggingBuilder builder, LoggingConfiguration configuration, NLogAspNetCoreOptions options)
{
return AddNLogWeb(builder, configuration, options);
}

/// <summary>
/// Configure NLog from API
/// </summary>
/// <param name="builder">The logging builder</param>
/// <param name="configuration">Config for NLog</param>
/// <param name="options">Options for logging to NLog with Dependency Injected loggers</param>
public static ILoggingBuilder AddNLogWeb(this ILoggingBuilder builder, LoggingConfiguration configuration, NLogAspNetCoreOptions options)
{
AddNLogLoggerProvider(builder.Services, null, options, (serviceProvider, config, opt) =>
{
Expand All @@ -163,6 +217,17 @@ public static ILoggingBuilder AddNLog(this ILoggingBuilder builder, LoggingConfi
/// <param name="factoryBuilder">Initialize NLog LogFactory with NLog LoggingConfiguration.</param>
/// <returns>ILoggingBuilder for chaining</returns>
public static ILoggingBuilder AddNLog(this ILoggingBuilder builder, Func<IServiceProvider, LogFactory> factoryBuilder)
{
return AddNLogWeb(builder, factoryBuilder);
}

/// <summary>
/// Enable NLog as logging provider for Microsoft Extension Logging
/// </summary>
/// <param name="builder"></param>
/// <param name="factoryBuilder">Initialize NLog LogFactory with NLog LoggingConfiguration.</param>
/// <returns>ILoggingBuilder for chaining</returns>
public static ILoggingBuilder AddNLogWeb(this ILoggingBuilder builder, Func<IServiceProvider, LogFactory> factoryBuilder)
{
AddNLogLoggerProvider(builder.Services, null, null, (serviceProvider, config, options) =>
{
Expand Down
11 changes: 0 additions & 11 deletions src/NLog.Web.AspNetCore/Config/SetupExtensionsBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Reflection;
using Microsoft.Extensions.Configuration;
using NLog.Config;
using NLog.Extensions.Logging;
using NLog.Web.DependencyInjection;

namespace NLog.Web
Expand All @@ -12,15 +10,6 @@ namespace NLog.Web
/// </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;
return setupBuilder.RegisterLayoutRenderer<ConfigSettingLayoutRenderer>("configsetting");
}

/// <summary>
/// Register the NLog.Web.AspNetCore LayoutRenderers
/// </summary>
Expand Down

0 comments on commit 8e2823a

Please sign in to comment.