static void Main(string[] args) { var syslogServer = new SyslogServer(listenAddress: IPAddress.Any); syslogServer.Start(OnMessageReceived); Console.WriteLine($"Server ready. Send syslog messages to {syslogServer.ListenAddress.ToString()} UDP port {syslogServer.UdpListenPort} or TCP port {syslogServer.TcpListenPort}."); Console.WriteLine("Press [ENTER] to stop"); Console.ReadLine(); syslogServer.Stop(); Console.WriteLine("Server stopped."); }
private void ToggleSyslogServer(bool start, SyslogServer syslogServer) { if (start) { ChosenOperation['S'] = "StopSyslogServer"; InitStreams(); syslogServer.Start(OnReceivedString, OnException); } else { ChosenOperation['S'] = "StartSyslogServer"; syslogServer.Stop(); DisposeStreams(); } }
private void ToggleSyslogServer(bool start, SyslogServer syslogServer) { buttonStartStopSyslogServer.Enabled = false; var operation = start ? "Stop" : "Start"; buttonStartStopSyslogServer.Name = $"button{operation}SyslogServer"; buttonStartStopSyslogServer.Text = $@"{operation} Syslog Server"; if (start) { syslogServer.Start(receivedStringAction, exceptionAction); } else { syslogServer.Stop(); } Action enableButton = () => buttonStartStopSyslogServer.Enabled = true; Task.Delay(500).ContinueWith(_ => Invoke(enableButton)); }