void ILogCollector.SubmitMessage(SyslogMessage message) { if (_disposed) { throw new ObjectDisposedException(GetType().FullName); } _queue.Enqueue(message); if (!_configured) { if (string.IsNullOrEmpty(_host)) { throw new InvalidOperationException("Unable to use SyslogTlsCollector without host name"); } else { lock (this) if (!_configured) { _deliveryThread.Start(); _configured = true; } } } }
private void LogbusMessageReceived(object sender, SyslogMessageEventArgs e) { SyslogMessage message = e.Message; if (message.Facility == SyslogFacility.Internally) { return; //Skip all syslog-internal messages } _messageQueue.Enqueue(message); }
void ILogCollector.SubmitMessage(SyslogMessage message) { if (Disposed) { throw new ObjectDisposedException(GetType().FullName); } if (_block || _withinCoalescenceWindow || !Running) { return; //Discard message } _messageQueue.Enqueue(message); }
private void LoopProducer(object queue) { long writes = 0; try { IFifoQueue <object> q = (IFifoQueue <object>)queue; while (true) { q.Enqueue(new object()); writes++; Thread.Sleep(0); } } catch (ThreadAbortException) { TestContext.WriteLine("Wrote {0} elements", writes); } }
private void ListenerLoop() { try { try { //Wait for first connection Log.Debug("Listening on TLS socket {0}", _server.LocalEndpoint.ToString()); using (TcpClient client = _server.AcceptTcpClient()) { using (SslStream stream = new SslStream(client.GetStream(), false, RemoteCertificateValidation, LocalCertificateSelection)) { stream.AuthenticateAsServer(CertificateUtilities.DefaultCertificate, false, SslProtocols.Tls, true); stream.ReadTimeout = 3600000; //1 hour while (true) { StringBuilder sb = new StringBuilder(); do { char nextChar = (char)stream.ReadByte(); if (char.IsDigit(nextChar)) { sb.Append(nextChar); } else if (nextChar == ' ') { break; } else { throw new FormatException("Invalid TLS encoding of Syslog message"); } } while (true); int charLen = int.Parse(sb.ToString(), CultureInfo.InvariantCulture); byte[] buffer = new byte[charLen]; int position = 0; do { int read = stream.Read(buffer, position, charLen); position += read; charLen -= read; } while (charLen > 0); _queue.Enqueue(buffer); } } } } catch (IOException) { if (!Running) { return; //OK } throw; } catch (SocketException) { if (!Running) { return; //OK } throw; } } catch (ThreadAbortException) { } catch (Exception ex) { OnError(new UnhandledExceptionEventArgs(ex, true)); Log.Error("Error receiving Syslog messages from Logbus-ng server"); Log.Debug("Error details: {0}", ex.Message); new Thread(delegate() { try { Stop(); } catch { } }).Start(); } }