refactor: Ersetzen der Methode CurrentDomainOnUnhandledException durch eine Lambda-Funktion zum Umgang mit nicht behandelten Ausnahmen

This commit is contained in:
Developer 02 2024-08-05 09:25:01 +02:00
parent fe01e04966
commit 7ab24c696b

View File

@ -16,7 +16,12 @@ namespace StaffDBServer
public static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
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();
@ -55,13 +60,5 @@ namespace StaffDBServer
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();
}
}
}