Esempio n. 1
0
        public SyslogTcpSink(SyslogTcpConfig config, BatchConfig batchConfig)
            : base(batchConfig.BatchSizeLimit, batchConfig.Period, batchConfig.QueueSizeLimit)
        {
            this.formatter       = config.Formatter;
            this.framer          = config.Framer;
            this.Host            = config.Host;
            this.Port            = config.Port;
            this.enableKeepAlive = config.KeepAlive;

            this.secureProtocols        = config.SecureProtocols;
            this.useTls                 = config.SecureProtocols != SslProtocols.None;
            this.certValidationCallback = config.CertValidationCallback;

            if (config.CertProvider?.Certificate != null)
            {
                this.clientCert = new X509Certificate2Collection(new [] { config.CertProvider.Certificate });
            }

            // You can't set socket options *and* connect to an endpoint using a hostname - if
            // keep-alive is enabled, resolve the hostname to an IP
            // See https://github.com/dotnet/corefx/issues/26840
            if (config.KeepAlive && RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                if (!IPAddress.TryParse(config.Host, out var addr))
                {
                    addr      = Dns.GetHostAddresses(config.Host).First(x => x.AddressFamily == AddressFamily.InterNetwork);
                    this.Host = addr.ToString();
                }
            }
        }
 public SyslogUdpSink(IPEndPoint endpoint, ISyslogFormatter formatter, BatchConfig batchConfig)
     : base(batchConfig.BatchSizeLimit, batchConfig.Period, batchConfig.QueueSizeLimit)
 {
     this.formatter = formatter;
     this.endpoint  = endpoint;
     this.client    = new UdpClient(endpoint.AddressFamily);
 }