diff --git a/src/NLog.Web.AspNetCore/AspNetExtensions.cs b/src/NLog.Web.AspNetCore/AspNetExtensions.cs index b9b70992..7d0dc151 100644 --- a/src/NLog.Web.AspNetCore/AspNetExtensions.cs +++ b/src/NLog.Web.AspNetCore/AspNetExtensions.cs @@ -110,12 +110,45 @@ public static LogFactory ConfigureNLog(this ILoggingBuilder builder, LoggingConf return LogManager.LogFactory; } + /// + /// Enable NLog as logging provider for Microsoft Extension Logging + /// + /// The logging builder + public static ILoggingBuilder AddNLogWeb(this ILoggingBuilder builder) + { + return builder.AddNLogWeb(NLogAspNetCoreOptions.Default); + } + + /// + /// Enable NLog as logging provider for Microsoft Extension Logging + /// + /// The logging builder + /// Options for logging to NLog with Dependency Injected loggers + public static ILoggingBuilder AddNLogWeb(this ILoggingBuilder builder, NLogAspNetCoreOptions options) + { + AddNLogLoggerProvider(builder.Services, null, options, (serviceProvider, config, opt) => + { + return CreateNLogLoggerProvider(serviceProvider, config, opt); + }); + return builder; + } + /// /// Apply NLog configuration from XML config. /// /// The logging builder /// Path to NLog configuration file, e.g. nlog.config. public static ILoggingBuilder AddNLog(this ILoggingBuilder builder, string configFileName) + { + return AddNLogWeb(builder, configFileName); + } + + /// + /// Apply NLog configuration from XML config. + /// + /// The logging builder + /// Path to NLog configuration file, e.g. nlog.config. + public static ILoggingBuilder AddNLogWeb(this ILoggingBuilder builder, string configFileName) { AddNLogLoggerProvider(builder.Services, null, null, (serviceProvider, config, options) => { @@ -134,7 +167,17 @@ public static ILoggingBuilder AddNLog(this ILoggingBuilder builder, string confi /// Config for NLog public static ILoggingBuilder AddNLog(this ILoggingBuilder builder, LoggingConfiguration configuration) { - return AddNLog(builder, configuration, null); + return AddNLogWeb(builder, configuration); + } + + /// + /// Configure NLog from API + /// + /// The logging builder + /// Config for NLog + public static ILoggingBuilder AddNLogWeb(this ILoggingBuilder builder, LoggingConfiguration configuration) + { + return AddNLogWeb(builder, configuration, null); } /// @@ -144,6 +187,17 @@ public static ILoggingBuilder AddNLog(this ILoggingBuilder builder, LoggingConfi /// Config for NLog /// Options for logging to NLog with Dependency Injected loggers public static ILoggingBuilder AddNLog(this ILoggingBuilder builder, LoggingConfiguration configuration, NLogAspNetCoreOptions options) + { + return AddNLogWeb(builder, configuration, options); + } + + /// + /// Configure NLog from API + /// + /// The logging builder + /// Config for NLog + /// Options for logging to NLog with Dependency Injected loggers + public static ILoggingBuilder AddNLogWeb(this ILoggingBuilder builder, LoggingConfiguration configuration, NLogAspNetCoreOptions options) { AddNLogLoggerProvider(builder.Services, null, options, (serviceProvider, config, opt) => { @@ -163,6 +217,17 @@ public static ILoggingBuilder AddNLog(this ILoggingBuilder builder, LoggingConfi /// Initialize NLog LogFactory with NLog LoggingConfiguration. /// ILoggingBuilder for chaining public static ILoggingBuilder AddNLog(this ILoggingBuilder builder, Func factoryBuilder) + { + return AddNLogWeb(builder, factoryBuilder); + } + + /// + /// Enable NLog as logging provider for Microsoft Extension Logging + /// + /// + /// Initialize NLog LogFactory with NLog LoggingConfiguration. + /// ILoggingBuilder for chaining + public static ILoggingBuilder AddNLogWeb(this ILoggingBuilder builder, Func factoryBuilder) { AddNLogLoggerProvider(builder.Services, null, null, (serviceProvider, config, options) => { diff --git a/src/NLog.Web.AspNetCore/Config/SetupExtensionsBuilderExtensions.cs b/src/NLog.Web.AspNetCore/Config/SetupExtensionsBuilderExtensions.cs index 722f1ec3..f8a95c75 100644 --- a/src/NLog.Web.AspNetCore/Config/SetupExtensionsBuilderExtensions.cs +++ b/src/NLog.Web.AspNetCore/Config/SetupExtensionsBuilderExtensions.cs @@ -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 @@ -12,15 +10,6 @@ namespace NLog.Web /// public static class SetupExtensionsBuilderExtensions { - /// - /// Replace with version from NLog.Extension.Logging when it has been released with NLog 4.7 - /// - internal static ISetupExtensionsBuilder RegisterConfigSettings(this ISetupExtensionsBuilder setupBuilder, IConfiguration configuration) - { - ConfigSettingLayoutRenderer.DefaultConfiguration = configuration; - return setupBuilder.RegisterLayoutRenderer("configsetting"); - } - /// /// Register the NLog.Web.AspNetCore LayoutRenderers ///