More .NET libraries
-
Rebex Total Pack
All Rebex .NET libraries together
Back to feature list...
Easy-to-use API
On this page:
Sending syslog messages
To send a syslog messages to a syslog server, just connect the SyslogClient
object and call the Send
method:
// create a SyslogClient instance using (var client = new Rebex.Net.SyslogClient()) { // connect to a syslog server client.Connect(hostname, port, SyslogTransportProtocol.Tcp); // send a message client.Send("Hello from Rebex Syslog client."); // send another message client.Send("Everything is working fine."); }
' create a SyslogClient instance Using client = New Rebex.Net.SyslogClient() ' connect to a syslog server client.Connect(hostname, port, SyslogTransportProtocol.Tcp) ' send a message client.Send("Hello from Rebex Syslog client.") ' send another message client.Send("Everything is working fine.") End Using
Launching syslog server
Launching a syslog server is simple:
- Bind the server to an endpoint.
- Register
MessageReceived
event to get notified about received messages. - Register
ErrorOccurred
event to get notified about errors. - Start the server.
// create a SyslogServer instance var server = new SyslogServer(); // bind endpoints server.Bind(SyslogServer.DefaultPort, SyslogTransportProtocol.Udp); server.Bind(SyslogServer.DefaultPort, SyslogTransportProtocol.Tcp); // register an event handler for received messages server.MessageReceived += (s, e) => { Console.WriteLine("Message from {0}: {1}", e.RemoteEndPoint, e.Message.Text); }; // 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();
' create a SyslogServer instance Dim server = New SyslogServer() ' bind endpoints server.Bind(SyslogServer.DefaultPort, SyslogTransportProtocol.Udp) server.Bind(SyslogServer.DefaultPort, SyslogTransportProtocol.Tcp) ' register an event handler for received messages AddHandler server.MessageReceived, Sub(s, e) Console.WriteLine("Message from {0}: {1}", e.RemoteEndPoint, e.Message.Text) ' register an event handler for errors AddHandler server.ErrorOccurred, Sub(s, e) Console.WriteLine("Error occurred ({0}): {1}", e.RemoteEndPoint, e.Error) ' start the server server.Start()
Back to feature list...