using ChatRoomContract; using NLog; namespace ChatRoom; internal class Server { /// /// Logger for this class. /// private Logger log = LogManager.GetCurrentClassLogger(); /// /// Configure loggin subsystem. /// private void ConfigureLogging() { var config = new NLog.Config.LoggingConfiguration(); var console = new NLog.Targets.ConsoleTarget("console") { Layout = @"${date:format=HH\:mm\:ss}|${level}| ${message} ${exception}" }; config.AddTarget(console); config.AddRuleForAllLevels(console); LogManager.Configuration = config; } /// /// Program body. /// private void Run() { //configure logging ConfigureLogging(); while (true) { try { var service = new ChatRoomService(Config.CreateConnection(), Config.ExchangeName, Config.ServerQueueName); log.Info("Server has been started."); //hang main thread while (true) { Thread.Sleep(1000); } } catch (Exception e) { //log exception log.Error(e, "Unhandled exception caught. Server will now restart."); //prevent console spamming Thread.Sleep(2000); } } } /// /// Program entry point. /// /// Command line arguments. static void Main(string[] args) { var self = new Server(); self.Run(); } }