64 lines
2.2 KiB
C#
64 lines
2.2 KiB
C#
using HRD.AppLogger;
|
|
using HRD.WebApi;
|
|
using Microsoft.AspNetCore;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using NLog.Web;
|
|
using System;
|
|
using System.Reflection;
|
|
|
|
namespace StaffDBServer
|
|
{
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
|
|
{
|
|
AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs) =>
|
|
{
|
|
ILoggerManager logger = new LoggerManager();
|
|
logger.LogException((Exception)unhandledExceptionEventArgs.ExceptionObject, "Application closed due to exception.");
|
|
NLog.LogManager.Flush();
|
|
};
|
|
|
|
IConfiguration configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json", true, true).Build();
|
|
|
|
WebApiConfig.Init(configuration, Assembly.GetExecutingAssembly().GetName());
|
|
|
|
ILoggerManager logger = new LoggerManager();
|
|
logger.LogWarn($"[Start WebApi Server] BaseDirectory: {AppDomain.CurrentDomain.BaseDirectory}; TargetFrameworkName: {AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName}");
|
|
|
|
try
|
|
{
|
|
CreateWebHostBuilder(args)
|
|
.Build()
|
|
.Run();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.LogException(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.Flush();
|
|
NLog.LogManager.Shutdown();
|
|
}
|
|
}
|
|
|
|
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
|
|
|
WebHost.CreateDefaultBuilder(args)
|
|
|
|
.ConfigureLogging(options => options.ClearProviders())
|
|
.UseStartup<Startup>().ConfigureLogging(logging =>
|
|
{
|
|
logging.ClearProviders();
|
|
logging.SetMinimumLevel(LogLevel.Warning);
|
|
})
|
|
.UseNLog();
|
|
}
|
|
} |