refactor: Projektdateien migriert. Cloud-NuGet-Pakete durch lokale NuGet-Projekte ersetzt.
This commit is contained in:
67
StaffDBServer/Program.cs
Normal file
67
StaffDBServer/Program.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
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 += CurrentDomainOnUnhandledException;
|
||||
|
||||
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();
|
||||
|
||||
private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
|
||||
|
||||
{
|
||||
ILoggerManager logger = new LoggerManager();
|
||||
logger.LogException((Exception)unhandledExceptionEventArgs.ExceptionObject, "Application closed due to exception.");
|
||||
NLog.LogManager.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user