First Initial
This commit is contained in:
68
Program.cs
Normal file
68
Program.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TestAPI01.Seed;
|
||||
using NLog.Web;
|
||||
|
||||
namespace Test01
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// NLog: setup the logger first to catch all errors
|
||||
// https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-2
|
||||
var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
|
||||
try
|
||||
{
|
||||
logger.Debug("Init main");
|
||||
|
||||
Console.Title = "BKK Application";
|
||||
|
||||
var host = BuildWebHost(args);
|
||||
|
||||
var config = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json", optional: false)
|
||||
.Build();
|
||||
|
||||
var enableSeedApplicationDb = Convert.ToBoolean(config.GetSection("EnableSeedApplicationDb").Value);
|
||||
|
||||
//SeedData.EnsureSeedData(host.Services, enableSeedApplicationDb);
|
||||
|
||||
host.Run();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
public static IWebHost BuildWebHost(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
|
||||
//NLog Config
|
||||
.ConfigureLogging(logging =>
|
||||
{
|
||||
logging.ClearProviders();
|
||||
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
|
||||
})
|
||||
.UseNLog() // NLog: setup NLog for Dependency injection
|
||||
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user