public void StartLogging() { lock (this) { if (_server != null) { return; } try { // New server _server = new SyslogServer(SyslogServer.DefaultAddress, _port); // Register for events _server.SyslogMessageReceived += _eventDelegate; // Start listening _server.Connect(); } catch (Exception) { if (_server != null) { _server.Close(); _server.SyslogMessageReceived -= _eventDelegate; _server = null; } throw; } } }
[Test] public void CreateServer() { SyslogServer srv = new SyslogServer(); srv.Connect(); Assert.IsTrue(srv.Connected, "Server connected"); srv.Close(); }
private void Connect() { if (_server != null) { return; } try { IPAddress ip = _specificIP; if (ip == null) { ip = SyslogServer.DefaultAddress; } _server = new SyslogServer(ip, _port); _server.SyslogMessageReceived += new SyslogServer.SyslogMessageDelegate(OnSyslogMessage); _server.Connect(); } catch (Exception) { if (_server != null) { _server.Close(); _server = null; } throw; } }