Skip to content

Commit

Permalink
extra helper
Browse files Browse the repository at this point in the history
  • Loading branch information
304NotModified committed Oct 7, 2017
1 parent 108b5f3 commit 1623e85
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion NLog.Web.AspNetCore/AspNetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static LoggingConfiguration ConfigureNLog(this IHostingEnvironment env, s
/// <summary>
/// Apply NLog configuration from XML config.
/// </summary>
/// <param name="fileName">absolute path NLog configuration file.</param>
/// <param name="fileName">Path to NLog configuration file, e.g. nlog.config. </param>
/// <returns>LoggingConfiguration for chaining</returns>
private static LoggingConfiguration ConfigureNLog(string fileName)
{
Expand Down
32 changes: 28 additions & 4 deletions NLog.Web.AspNetCore/NLogStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,38 @@

namespace NLog.Web
{
/// <summary>
/// NLog start helper
/// </summary>
public static class NLogStart
{
public static Logger InitLogger(string nlogConfig)
/// <summary>
/// Init the NLog
///
/// If this method is used, there is no need for ConfigureNLog
/// </summary>
/// <param name="fileName">Path to NLog configuration file, e.g. nlog.config. </param>>
/// <returns>Logger to start logging</returns>
public static Logger InitLogger(string fileName)
{
//register yourself
ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly);
var configuration = new XmlLoggingConfiguration(fileName);

return InitLogger(configuration);
}

LogManager.Configuration = new XmlLoggingConfiguration(nlogConfig);
/// <summary>
/// Init the NLog
///
/// If this method is used, there is no need for ConfigureNLog
/// </summary>
/// <param name="configuration">NLog config</param>>
/// <returns>Logger to start logging</returns>
public static Logger InitLogger(LoggingConfiguration configuration)
{
//register yourself, so <extension> isn't needed.
ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly);

LogManager.Configuration = configuration;
var logger = LogManager.GetCurrentClassLogger();
return logger;
}
Expand Down

0 comments on commit 1623e85

Please sign in to comment.