static void Main(string[] args) { ExitEvent = new ManualResetEvent(false); MigrateSettingsDirectory(); try { if (!Directory.Exists(AppConfigDirectory)) { IsFirstRun = true; Directory.CreateDirectory(AppConfigDirectory); } Console.WriteLine("App config/log directory: " + AppConfigDirectory); } catch (Exception ex) { MessageBox.Show("Could not create settings directory. " + ex.Message); Application.Exit(); return; } var logConfig = new LoggingConfiguration(); var logFile = new FileTarget(); logConfig.AddTarget("file", logFile); logFile.Layout = "${longdate} ${level} ${message} \n ${exception:format=ToString}\n"; logFile.FileName = Path.Combine(AppConfigDirectory, "log.txt"); logFile.ArchiveFileName = "log.{#####}.txt"; logFile.ArchiveAboveSize = 500000; logFile.MaxArchiveFiles = 1; logFile.KeepFileOpen = false; logFile.ArchiveNumbering = ArchiveNumberingMode.DateAndSequence; var logFileRule = new LoggingRule("*", LogLevel.Debug, logFile); logConfig.LoggingRules.Add(logFileRule); if (Program.IsWindows) { #if !__MonoCS__ var logAlert = new MessageBoxTarget(); logConfig.AddTarget("alert", logAlert); logAlert.Layout = "${message}"; logAlert.Caption = "Alert"; var logAlertRule = new LoggingRule("*", LogLevel.Fatal, logAlert); logConfig.LoggingRules.Add(logAlertRule); #endif } var logConsole = new ConsoleTarget(); logConfig.AddTarget("console", logConsole); logConsole.Layout = "${longdate} ${level} ${message} ${exception:format=ToString}"; var logConsoleRule = new LoggingRule("*", LogLevel.Debug, logConsole); logConfig.LoggingRules.Add(logConsoleRule); LogManager.Configuration = logConfig; LoggerInstance = LogManager.GetCurrentClassLogger(); ReadSettingsFile(); var serverTask = Task.Run(async () => { ServerInstance = new Server(); await ServerInstance.Start(); }); try { if (Program.IsWindows) { #if !__MonoCS__ Application.Run(new Main()); #endif } } catch (Exception) { } Console.WriteLine("Running in headless mode."); Task.WaitAll(serverTask); Console.WriteLine("Server thread exit"); }
public static void RestartServer() { ServerInstance.Stop(); ServerInstance = null; var serverTask = Task.Run(async () => { ServerInstance = new Server(); await ServerInstance.Start(); }); Task.WaitAll(serverTask); }