diff --git a/examples/NetCore2/ConsoleExample/Program.cs b/examples/NetCore2/ConsoleExample/Program.cs index 85607bf5..c85032c0 100644 --- a/examples/NetCore2/ConsoleExample/Program.cs +++ b/examples/NetCore2/ConsoleExample/Program.cs @@ -9,15 +9,28 @@ class Program { static void Main(string[] args) { - var servicesProvider = BuildDi(); - var runner = servicesProvider.GetRequiredService(); - - runner.DoAction("Action1"); - - Console.WriteLine("Press ANY key to exit"); - Console.ReadLine(); - - NLog.LogManager.Shutdown(); // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) + var logger = NLog.LogManager.LoadConfiguration("nlog.config").GetCurrentClassLogger(); + try + { + var servicesProvider = BuildDi(); + var runner = servicesProvider.GetRequiredService(); + + runner.DoAction("Action1"); + + Console.WriteLine("Press ANY key to exit"); + Console.ReadLine(); + } + catch (Exception ex) + { + //NLog: catch setup errors + logger.Error(ex, "Stopped program because of exception"); + throw; + } + finally + { + // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) + NLog.LogManager.Shutdown(); + } } @@ -38,8 +51,6 @@ private static IServiceProvider BuildDi() //configure NLog loggerFactory.AddNLog(new NLogProviderOptions { CaptureMessageTemplates = true, CaptureMessageProperties = true }); - loggerFactory.ConfigureNLog("nlog.config"); - return serviceProvider; } } @@ -58,7 +69,5 @@ public void DoAction(string name) { _logger.LogDebug(20, "Doing hard work! {Action}", name); } - - } } diff --git a/examples/NetCore2/ConsoleExample/nlog.config b/examples/NetCore2/ConsoleExample/nlog.config index 710225a9..d31b5ead 100644 --- a/examples/NetCore2/ConsoleExample/nlog.config +++ b/examples/NetCore2/ConsoleExample/nlog.config @@ -6,21 +6,17 @@ internalLogFile="c:\temp\console-example-internal.log" internalLogLevel="Info" > - - - - - + + - - + \ No newline at end of file diff --git a/src/NLog.Extensions.Logging/Extensions/ConfigureExtensions.cs b/src/NLog.Extensions.Logging/Extensions/ConfigureExtensions.cs index b956f746..af0415e0 100644 --- a/src/NLog.Extensions.Logging/Extensions/ConfigureExtensions.cs +++ b/src/NLog.Extensions.Logging/Extensions/ConfigureExtensions.cs @@ -108,6 +108,7 @@ private static void SafeAddHiddenAssembly(string assemblyName, bool logOnExcepti /// /// relative path to NLog configuration file. /// Current configuration for chaining. + [Obsolete("Instead use NLog.LogManager.LoadConfiguration()")] public static LoggingConfiguration ConfigureNLog(this ILoggerFactory loggerFactory, string configFileRelativePath) { ConfigureHiddenAssemblies(); @@ -120,6 +121,7 @@ public static LoggingConfiguration ConfigureNLog(this ILoggerFactory loggerFacto /// /// New NLog config. /// Current configuration for chaining. + [Obsolete("Instead assign property NLog.LogManager.Configuration")] public static LoggingConfiguration ConfigureNLog(this ILoggerFactory loggerFactory, LoggingConfiguration config) { ConfigureHiddenAssemblies();