private static void StartSyslogServer() { _server = new SyslogServer(514); _server.MessageReceived += (sender, eventArgs) => { var message = eventArgs.Message.Text; Console.WriteLine(message); Task.Factory.StartNew(async(s) => await WriteMessageToLogFile(s.ToString()), message); }; _server.Start(); }
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)); }