2020-10-31 15:57:19 +01:00
|
|
|
using Birdmap.DAL;
|
2020-10-21 11:05:17 +02:00
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2020-10-31 15:57:19 +01:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-10-21 11:05:17 +02:00
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2020-10-25 16:15:06 +01:00
|
|
|
using NLog;
|
|
|
|
using NLog.Web;
|
|
|
|
using System;
|
2020-10-21 11:05:17 +02:00
|
|
|
|
2020-11-08 23:29:50 +01:00
|
|
|
namespace Birdmap.API
|
2020-10-21 11:05:17 +02:00
|
|
|
{
|
|
|
|
public class Program
|
|
|
|
{
|
|
|
|
public static void Main(string[] args)
|
|
|
|
{
|
2020-10-25 16:15:06 +01:00
|
|
|
var logger = NLogBuilder.ConfigureNLog("NLog.config").GetCurrentClassLogger();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-10-31 15:57:19 +01:00
|
|
|
logger.Debug("Building host...");
|
|
|
|
var host = CreateHostBuilder(args).Build();
|
|
|
|
|
|
|
|
logger.Debug("Seeding database...");
|
|
|
|
SeedDatabase(host);
|
|
|
|
|
|
|
|
logger.Debug("Running host...");
|
|
|
|
host.Run();
|
2020-10-25 16:15:06 +01:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
logger.Error(ex, "Exception occurred in Main.");
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
LogManager.Shutdown();
|
|
|
|
}
|
2020-10-21 11:05:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
|
|
Host.CreateDefaultBuilder(args)
|
|
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
|
|
{
|
|
|
|
webBuilder.UseStartup<Startup>();
|
2020-10-25 16:15:06 +01:00
|
|
|
}).ConfigureLogging(logging =>
|
|
|
|
{
|
|
|
|
logging.ClearProviders();
|
|
|
|
logging.AddConsole();
|
|
|
|
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
|
|
|
|
})
|
|
|
|
.UseNLog();
|
2020-10-31 15:57:19 +01:00
|
|
|
|
|
|
|
private static void SeedDatabase(IHost host)
|
|
|
|
{
|
|
|
|
using var scope = host.Services.CreateScope();
|
|
|
|
var dbInitializer = scope.ServiceProvider.GetRequiredService<DbInitializer>();
|
|
|
|
|
|
|
|
dbInitializer.Initialize();
|
|
|
|
}
|
2020-10-21 11:05:17 +02:00
|
|
|
}
|
|
|
|
}
|