Ejemplo n.º 1
0
 /// <summary>
 /// Checks if the tcp connection is healthy and that the host hasn't been modified,
 /// if it has then the connection is reset.
 /// </summary>
 /// <param name="renderedFluentdHost">Host name of fluentd.</param>
 protected void CheckConnectionIsValid(string renderedFluentdHost)
 {
     if (this._client == null || !this._client.Connected || _fluentdHost != renderedFluentdHost)
     {
         ResetConnection();
         _fluentdHost = renderedFluentdHost;
         InitiateTCPConnection();
         if (this.UseSsl)
         {
             SetUpConnectionStream();
         }
         else
         {
             SetUpInsecureConnectionStream();
         }
         this._packer = new FluentdPacker(this._stream);
     }
 }
Ejemplo n.º 2
0
 protected void Cleanup()
 {
     try
     {
         this.stream?.Dispose();
         this.client?.Close();
     }
     catch (Exception ex)
     {
         NLog.Common.InternalLogger.Warn("Fluentd Close - " + ex.ToString());
     }
     finally
     {
         this.stream  = null;
         this.client  = null;
         this.emitter = null;
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Resets all objects related to the fluentd connection.
 /// </summary>
 protected void ResetConnection()
 {
     try
     {
         this._stream?.Dispose();
         this._client?.Close();
     }
     catch (Exception ex)
     {
         NLog.Common.InternalLogger.Warn("Fluentd: Connection Reset Error  - " + ex.ToString());
     }
     finally
     {
         this._stream = null;
         this._client = null;
         this._packer = null;
     }
 }
Ejemplo n.º 4
0
        private void ConnectClient()
        {
            NLog.Common.InternalLogger.Debug("Fluentd Connecting to {0}:{1}, SSL:{2}", this.Host, this.Port, this.useSsl);

            try
            {
                this.client.Connect(this.Host, this.Port);
            }
            catch (SocketException se)
            {
                InternalLogger.Error("Fluentd Extension Failed to connect against {0}:{1}", this.Host, this.Port);
                throw;
            }

            if (this.useSsl)
            {
                SslStream sslStream = new SslStream(new BufferedStream(this.client.GetStream()),
                                                    false,
                                                    new RemoteCertificateValidationCallback(ValidateServerCertificate),
                                                    null,
                                                    EncryptionPolicy.RequireEncryption);
                try
                {
                    sslStream.AuthenticateAsClient(this.Host, null, SslProtocols.Tls12, true);
                    this.stream = sslStream;
                }
                catch (AuthenticationException e)
                {
                    InternalLogger.Error("Fluentd Extension Failed to authenticate against {0}:{1}", this.Host, this.Port);
                    InternalLogger.Error("Exception: {0}", e.Message);
                    client.Close();
                    throw;
                }
            }
            else
            {
                this.stream = new BufferedStream(this.client.GetStream());
            }
            this.emitter = new FluentdPacker(this.stream);
        }