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
  • Loading branch information
snakefoot committed Aug 19, 2020
1 parent 5c38805 commit c8cd651
Showing 1 changed file with 66 additions and 1 deletion.
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

0 comments on commit c8cd651

Please sign in to comment.