SyslogServer
This sample launches a Syslog server.
The sample is a console utility that launches Syslog server on its default port (514) listening for UDP or TCP connections.
If a PFX file (and optionally its password) is specified, it also enables TLS connections on its default port (6514).
Usage
> SyslogServer
> SyslogServer "c:\data\server.pfx"
> SyslogServer "c:\data\server.pfx" "TopSecret"
C#
// create Syslog server instance var server = new SyslogServer(); // bind desired endpoints server.Bind(SyslogServer.DefaultPort, SyslogTransportProtocol.Udp); server.Bind(SyslogServer.DefaultPort, SyslogTransportProtocol.Tcp); // register an event handler for received messages server.MessageReceived += (s, e) => { // insert received message to a collection for further processing Queue.Add(e.Message); }; // register an event handler for errors server.ErrorOccurred += (s, e) => { Console.WriteLine("Error occurred ({0}): {1}", e.RemoteEndPoint, e.Error); }; // start the server server.Start();
The sample uses System.Collections.Concurrent.BlockingCollection
(from .NET 4.0)
to safely process received messages in a background thread.
C#
private void ConsumeSyslogMessages() { // process received messages foreach (var message in Queue.GetConsumingEnumerable()) { Console.WriteLine("Received message: {0}", message.Text); } }