diff --git a/samples/demos/belgrade-product-catalog-demo/Program.cs b/samples/demos/belgrade-product-catalog-demo/Program.cs index ed4fa91b..d66629fc 100644 --- a/samples/demos/belgrade-product-catalog-demo/Program.cs +++ b/samples/demos/belgrade-product-catalog-demo/Program.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using NLog; using NLog.Web; using System.IO; @@ -9,15 +10,22 @@ namespace ProductCatalog { public static void Main(string[] args) { - var host = new WebHostBuilder() - .UseKestrel() - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseIISIntegration() - .UseNLog() - .UseStartup() - .Build(); + NLogBuilder.ConfigureNLog("nlog.config"); + try + { + var host = new WebHostBuilder() + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseNLog() + .UseStartup() + .Build(); - host.Run(); + host.Run(); + } finally + { + LogManager.Shutdown(); + } } } } diff --git a/samples/demos/belgrade-product-catalog-demo/Startup.cs b/samples/demos/belgrade-product-catalog-demo/Startup.cs index e607e292..44d43335 100644 --- a/samples/demos/belgrade-product-catalog-demo/Startup.cs +++ b/samples/demos/belgrade-product-catalog-demo/Startup.cs @@ -23,7 +23,8 @@ namespace ProductCatalog { public Startup(IHostingEnvironment env) { - env.ConfigureNLog("nlog.config"); + // Deprecated way to initialize NLog form nlog.config, but works if you don't copy file to /bin. + //env.ConfigureNLog("nlog.config"); var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) @@ -86,12 +87,7 @@ namespace ProductCatalog loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); loggerFactory.AddSerilog(); - - //add NLog to ASP.NET Core - loggerFactory.AddNLog(); - NLog.LogManager.ThrowExceptions = true; - NLog.LogManager.ThrowConfigExceptions = true; - + app.UseSession(); app.UseStaticFiles(); app.UseMvc(routes => diff --git a/samples/demos/belgrade-product-catalog-demo/belgrade-product-catalog-demo.csproj b/samples/demos/belgrade-product-catalog-demo/belgrade-product-catalog-demo.csproj index 00bc490a..15f73df8 100644 --- a/samples/demos/belgrade-product-catalog-demo/belgrade-product-catalog-demo.csproj +++ b/samples/demos/belgrade-product-catalog-demo/belgrade-product-catalog-demo.csproj @@ -61,4 +61,10 @@ + + + Always + + +