Skip to content

Commit

Permalink
Merge pull request #195 from NLog/ConfigureLogging-netcore2
Browse files Browse the repository at this point in the history
add ConfigureNLog on ILoggingBuilder
  • Loading branch information
304NotModified authored Oct 12, 2017
2 parents 41da1c0 + e3e9b36 commit d2536a3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
29 changes: 27 additions & 2 deletions NLog.Web.AspNetCore/AspNetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@ private static LoggingConfiguration ConfigureNLog(string fileName)

#if NETSTANDARD2_0

/// <summary>
/// Apply NLog configuration from XML config.
///
/// This call is not needed when <see cref="NLogBuilder.ConfigureNLog(string)"/> is used.
/// </summary>
/// <param name="builder">The logging builder</param>
/// <param name="configFileName">Path to NLog configuration file, e.g. nlog.config. </param>>
/// <returns>LogFactory to get loggers, add events etc</returns>
public static LogFactory ConfigureNLog(this ILoggingBuilder builder, string configFileName)
{
return NLogBuilder.ConfigureNLog(configFileName);
}

/// <summary>
/// Configure NLog from API
///
/// This call is not needed when <see cref="NLogBuilder.ConfigureNLog(LoggingConfiguration)"/> is used.
/// </summary>
/// <param name="builder">The logging builder</param>
/// <param name="configuration">Config for NLog</param>
/// <returns>LogFactory to get loggers, add events etc</returns>
public static LogFactory ConfigureNLog(this ILoggingBuilder builder, LoggingConfiguration configuration)
{
return NLogBuilder.ConfigureNLog(configuration);
}

/// <summary>
/// Use NLog for Dependency Injected loggers.
Expand Down Expand Up @@ -89,7 +114,7 @@ public static IWebHostBuilder UseNLog(this IWebHostBuilder builder, NLogAspNetCo
ServiceLocator.ServiceProvider = serviceProvider;

NLogBuilder.RegisterNLogWebAspNetCore();

LogManager.Configuration?.Reload();
return new NLogLoggerFactory(options);

Expand All @@ -100,7 +125,7 @@ public static IWebHostBuilder UseNLog(this IWebHostBuilder builder, NLogAspNetCo
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
}





Expand Down
12 changes: 6 additions & 6 deletions NLog.Web.AspNetCore/NLogBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ internal static void RegisterNLogWebAspNetCore()
}

/// <summary>
/// Configure NLog
/// Configure NLog from XML config.
/// </summary>
/// <param name="fileName">Path to NLog configuration file, e.g. nlog.config. </param>>
/// <param name="configFileName">Path to NLog configuration file, e.g. nlog.config. </param>>
/// <returns>LogFactory to get loggers, add events etc</returns>
public static LogFactory ConfigureNLog(string fileName)
public static LogFactory ConfigureNLog(string configFileName)
{
RegisterNLogWebAspNetCore();
return ConfigureNLog(new XmlLoggingConfiguration(fileName));
return ConfigureNLog(new XmlLoggingConfiguration(configFileName));
}

/// <summary>
/// Configure NLog
/// Configure NLog from API
/// </summary>
/// <param name="configuration"></param>
/// <param name="configuration">Config for NLog</param>
/// <returns>LogFactory to get loggers, add events etc</returns>
public static LogFactory ConfigureNLog(LoggingConfiguration configuration)
{
Expand Down

0 comments on commit d2536a3

Please sign in to comment.