LogentriesCore.Net.LeClient.Connect C# (CSharp) Method

Connect() public method

public Connect ( ) : void
return void
        public void Connect()
        {
            m_Client = new TcpClient(m_ServerAddr, m_TcpPort);
            m_Client.NoDelay = true;

            // on Azure sockets will be closed after some minutes idle.
            // which for some reason messes up this library causing it to lose data.
            
            // turn on keepalive, to keep the sockets open.
            // I don't really understand why this helps the problem, since the socket already has NoDelay set
            // so data should be sent immediately. And indeed it does appear to be sent promptly when it works.
            m_Client.Client.SetSocketOption( SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);

            // set timeouts to 10 seconds idle before keepalive, 1 second between repeats, 
            SetSocketKeepAliveValues(m_Client, 10 *1000, 1000);
            
            m_Stream = m_Client.GetStream();

            if (m_UseSsl)
            {
                m_SslStream = new SslStream(m_Stream, false, (sender, certificate, chain, sslPolicyErrors) =>
                {
                    // HACK-HACK: Do not check the server name until our LogEntries forwarder is not ready.
                    if (sslPolicyErrors == SslPolicyErrors.None || sslPolicyErrors == SslPolicyErrors.RemoteCertificateNameMismatch)
                    {
                        return true;
                    }

                    return false;
                }
                );
                m_SslStream.AuthenticateAsClient(m_ServerAddr);

            }
        }

Usage Example

Exemplo n.º 1
0
        protected virtual void OpenConnection()
        {
            try
            {
                if (LeClient == null)
                {
                    // Create LeClient instance providing all needed parameters. If DataHub-related properties
                    // have not been overridden by log4net or NLog configurators, then DataHub is not used,
                    // because m_UseDataHub == false by default.
                    LeClient = new LeClient(m_UseHttpPut, m_UseSsl, m_UseDataHub, m_DataHubAddr, m_DataHubPort);
                }

                LeClient.Connect();

                if (m_UseHttpPut)
                {
                    var header = String.Format("PUT /{0}/hosts/{1}/?realtime=1 HTTP/1.1\r\n\r\n", m_AccountKey, m_Location);
                    LeClient.Write(ASCII.GetBytes(header), 0, header.Length);
                }
            }
            catch (Exception ex)
            {
                throw new IOException("An error occurred while opening the connection.", ex);
            }
        }
All Usage Examples Of LogentriesCore.Net.LeClient::Connect