11using System ;
2- using System . IO ;
32using System . Reflection ;
43using Microsoft . Extensions . Logging ;
54using NLog . Common ;
@@ -12,7 +11,6 @@ namespace NLog.Extensions.Logging
1211 /// </summary>
1312 public static class ConfigureExtensions
1413 {
15-
1614 /// <summary>
1715 /// Enable NLog as logging provider in .NET Core.
1816 /// </summary>
@@ -32,7 +30,6 @@ public static ILoggerFactory AddNLog(this ILoggerFactory factory)
3230 public static ILoggerFactory AddNLog ( this ILoggerFactory factory , NLogProviderOptions options )
3331 {
3432 ConfigureHiddenAssemblies ( ) ;
35-
3633 using ( var provider = new NLogLoggerProvider ( options ) )
3734 {
3835 factory . AddProvider ( provider ) ;
@@ -59,8 +56,6 @@ public static ILoggingBuilder AddNLog(this ILoggingBuilder factory)
5956 /// <returns>ILoggerFactory for chaining</returns>
6057 public static ILoggingBuilder AddNLog ( this ILoggingBuilder factory , NLogProviderOptions options )
6158 {
62- ConfigureHiddenAssemblies ( ) ;
63-
6459 using ( var provider = new NLogLoggerProvider ( options ) )
6560 {
6661 factory . AddProvider ( provider ) ;
@@ -74,22 +69,21 @@ public static ILoggingBuilder AddNLog(this ILoggingBuilder factory, NLogProvider
7469 /// </summary>
7570 private static void ConfigureHiddenAssemblies ( )
7671 {
77-
72+ #if NETCORE1_0
7873 InternalLogger . Trace ( "Hide assemblies for callsite" ) ;
7974
80- #if NETCORE1_0
8175 SafeAddHiddenAssembly ( "Microsoft.Logging" ) ;
82- #endif
8376
8477 SafeAddHiddenAssembly ( "Microsoft.Extensions.Logging" ) ;
8578 SafeAddHiddenAssembly ( "Microsoft.Extensions.Logging.Abstractions" ) ;
8679 SafeAddHiddenAssembly ( "NLog.Extensions.Logging" ) ;
8780
8881 //try the Filter ext, this one is not mandatory so could fail
8982 SafeAddHiddenAssembly ( "Microsoft.Extensions.Logging.Filter" , false ) ;
90-
83+ #endif
9184 }
9285
86+ #if NETCORE1_0
9387 private static void SafeAddHiddenAssembly ( string assemblyName , bool logOnException = true )
9488 {
9589 try
@@ -106,6 +100,7 @@ private static void SafeAddHiddenAssembly(string assemblyName, bool logOnExcepti
106100 }
107101 }
108102 }
103+ #endif
109104
110105 /// <summary>
111106 /// Apply NLog configuration from XML config.
@@ -115,14 +110,8 @@ private static void SafeAddHiddenAssembly(string assemblyName, bool logOnExcepti
115110 /// <returns>Current configuration for chaining.</returns>
116111 public static LoggingConfiguration ConfigureNLog ( this ILoggerFactory loggerFactory , string configFileRelativePath )
117112 {
118- #if NETCORE1_0 && ! NET451
119- var rootPath = System . AppContext . BaseDirectory ;
120- #else
121- var rootPath = AppDomain . CurrentDomain . BaseDirectory ;
122- #endif
123-
124- var fileName = Path . Combine ( rootPath , configFileRelativePath ) ;
125- return ConfigureNLog ( fileName ) ;
113+ ConfigureHiddenAssemblies ( ) ;
114+ return LogManager . LoadConfiguration ( configFileRelativePath ) . Configuration ;
126115 }
127116
128117 /// <summary>
@@ -133,19 +122,7 @@ public static LoggingConfiguration ConfigureNLog(this ILoggerFactory loggerFacto
133122 /// <returns>Current configuration for chaining.</returns>
134123 public static LoggingConfiguration ConfigureNLog ( this ILoggerFactory loggerFactory , LoggingConfiguration config )
135124 {
136- LogManager . Configuration = config ;
137-
138- return config ;
139- }
140-
141- /// <summary>
142- /// Apply NLog configuration from XML config.
143- /// </summary>
144- /// <param name="fileName">absolute path NLog configuration file.</param>
145- /// <returns>Current configuration for chaining.</returns>
146- private static LoggingConfiguration ConfigureNLog ( string fileName )
147- {
148- var config = new XmlLoggingConfiguration ( fileName , true ) ;
125+ ConfigureHiddenAssemblies ( ) ;
149126 LogManager . Configuration = config ;
150127 return config ;
151128 }
0 commit comments