Skip to content

Commit

Permalink
update with NLogBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
304NotModified committed Oct 10, 2017
1 parent 6f861ea commit eb5a1e2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
1 change: 1 addition & 0 deletions NLog.Web.AspNetCore/NLog.Web.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Routing.Abstractions" Version="2.0.0" />
<PackageReference Include="NLog" Version="4.5.0-beta04" />

</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
using System;
#if NETSTANDARD2_0


using System;
using System.Collections.Generic;
using System.Reflection;
using NLog.Common;
using NLog.Config;

namespace NLog.Web
{


/// <summary>
/// NLog start helper
/// NLog helper for ASP.NET Standard 2
/// </summary>
public static class NLogStart
public static class NLogBuilder
{

static NLogStart()
static NLogBuilder()
{
//do actions before loading config
try
{
//register yourself, so <extension> isn't needed.
Expand All @@ -27,30 +33,25 @@ static NLogStart()
}

/// <summary>
/// Init the NLog
///
/// If this method is used, there is no need for ConfigureNLog
/// Configure NLog
/// </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)
/// <returns>LogFactory to get loggers, add events etc</returns>
public static LogFactory ConfigureNLog(string fileName)
{
var configuration = new XmlLoggingConfiguration(fileName);
return InitLogger(configuration);
return ConfigureNLog(new XmlLoggingConfiguration(fileName));
}

/// <summary>
/// Init the NLog
///
/// If this method is used, there is no need for ConfigureNLog
/// Configure NLog
/// </summary>
/// <param name="configuration">NLog config</param>>
/// <returns>Logger to start logging</returns>
public static Logger InitLogger(LoggingConfiguration configuration)
/// <param name="configuration"></param>
/// <returns>LogFactory to get loggers, add events etc</returns>
public static LogFactory ConfigureNLog(LoggingConfiguration configuration)
{
LogManager.Configuration = configuration;
var logger = LogManager.GetCurrentClassLogger();
return logger;
return LogManager.LogFactory;
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Program
public static void Main(string[] args)
{
// NLog: setup the logger first to catch all errors
var logger = NLogStart.InitLogger("NLog.config");
var logger = NLogBuilder.ConfigureNLog("NLog.config").GetCurrentClassLogger();
try
{
logger.Debug("init main");
Expand Down

0 comments on commit eb5a1e2

Please sign in to comment.