81 lines
2.6 KiB
C#
81 lines
2.6 KiB
C#
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 = "TB320 EVA Application";
|
|
|
|
var host = BuildWebHost(args);
|
|
|
|
var config = new ConfigurationBuilder()
|
|
.SetBasePath(Directory.GetCurrentDirectory())
|
|
.AddJsonFile("appsettings.json", optional: false)
|
|
.Build();
|
|
|
|
var enableMigration = Environment.GetEnvironmentVariable("MIGRATION");
|
|
|
|
if (!string.IsNullOrEmpty(enableMigration))
|
|
{
|
|
MigrationData.EnsureMigration(host.Services);
|
|
//return;
|
|
}
|
|
|
|
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)
|
|
.ConfigureAppConfiguration((hostingContext, config) =>
|
|
{
|
|
config.AddEnvironmentVariables();
|
|
})
|
|
.UseStartup<Startup>()
|
|
|
|
//NLog Config
|
|
.ConfigureLogging(logging =>
|
|
{
|
|
logging.ClearProviders();
|
|
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
|
|
})
|
|
.UseNLog() // NLog: setup NLog for Dependency injection
|
|
|
|
.Build();
|
|
}
|
|
}
|