Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced AddNLogWeb to avoid conflict with AddNLog from NLog.Extension.Logging #602

Merged
merged 1 commit into from
Sep 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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