public static void Main(string[] args) { var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); var host = CreateHostBuilder(args).Build(); CreateDbIfNotExists(host); try { //设置NLog NLogHelper.Set(logger); logger.Debug("初始化 Main !"); host.Run(); } catch (Exception exception) { if (!(exception is MessageBox)) { //NLog: catch setup errors logger.Error(exception, "由于异常而停止程序!"); } } finally { // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) NLog.LogManager.Shutdown(); } }