SysLogWriter

Syslog-based ILogWriter implementation

This sample shows how to implement a Syslog-based ILogWriter suitable for Rebex components.

The sample app negotiates a TLS session with test.rebex.net server and logs the progress of the TLS negotiation to a specified Syslog server.

Usage

> SysLogWriter UDP localhost
> SysLogWriter TCP localhost:514

C#

// derive from LogWriterBase
public class SysLogWriter : LogWriterBase
{
    private readonly SyslogClient _client = new SyslogClient();

    public SysLogWriter(string serverName, int port, SyslogTransportProtocol protocol)
    {
        // connect to desired Syslog server
        _client.Connect(serverName, port, protocol);
    }

    // implement logic by overriding WriteMessage()
    protected override void WriteMessage(string message)
    {
        _client.Send(message);
    }

    // handle dispose
    protected override void Dispose(bool disposing)
    {
        if (disposing) _client.Close();
    }
}