public async Task Should_send_logs_to_tcp_syslog_service()
        {
            var sink = new SyslogTcpSink(this.tcpConfig, this.batchConfig);
            var log  = GetLogger(sink);

            var receiver = new TcpSyslogReceiver(this.endpoint, null, SECURE_PROTOCOLS);

            receiver.MessageReceived += (_, msg) =>
            {
                this.messagesReceived.Add(msg);
                this.countdown.Signal();
            };

            var receiveTask = receiver.Start(this.cts.Token);

            log.Information("This is test message 1");
            log.Warning("This is test message 2");
            log.Error("This is test message 3");

            await this.countdown.WaitAsync(20000, this.cts.Token);

            // The server should have received all 3 messages sent by the sink
            this.messagesReceived.Count.ShouldBe(3);
            this.messagesReceived.ShouldContain(x => x.StartsWith("<134>"));
            this.messagesReceived.ShouldContain(x => x.StartsWith("<132>"));
            this.messagesReceived.ShouldContain(x => x.StartsWith("<131>"));

            sink.Dispose();
            this.cts.Cancel();
            await receiveTask;
        }
        public async Task Should_send_logs_to_secure_tcp_syslog_service()
        {
            this.tcpConfig.KeepAlive              = false; // Just to test the negative path
            this.tcpConfig.SecureProtocols        = SECURE_PROTOCOLS;
            this.tcpConfig.CertProvider           = new CertificateProvider(ClientCert);
            this.tcpConfig.CertValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
            {
                // So we know this callback was called
                this.serverCertificate = new X509Certificate2(certificate);
                return(true);
            };

            var sink = new SyslogTcpSink(this.tcpConfig, this.batchConfig);
            var log  = GetLogger(sink);

            var receiver = new TcpSyslogReceiver(this.endpoint, ServerCert, SECURE_PROTOCOLS);

            receiver.MessageReceived += (_, msg) =>
            {
                this.messagesReceived.Add(msg);
                this.countdown.Signal();
            };

            receiver.ClientAuthenticated += (_, cert) => this.clientCertificate = cert;

            var receiveTask = receiver.Start(this.cts.Token);

            log.Information("This is test message 1");
            log.Warning("This is test message 2");
            log.Error("This is test message 3");

            await this.countdown.WaitAsync(20000, this.cts.Token);

            // The server should have received all 3 messages sent by the sink
            this.messagesReceived.Count.ShouldBe(3);
            this.messagesReceived.ShouldContain(x => x.StartsWith("<134>"));
            this.messagesReceived.ShouldContain(x => x.StartsWith("<132>"));
            this.messagesReceived.ShouldContain(x => x.StartsWith("<131>"));

            // The sink should have presented the client certificate to the server
            this.clientCertificate.Thumbprint
            .ShouldBe(ClientCert.Thumbprint, StringCompareShould.IgnoreCase);

            // The sink should have seen the server's certificate in the validation callback
            this.serverCertificate.Thumbprint
            .ShouldBe(ServerCert.Thumbprint, StringCompareShould.IgnoreCase);

            sink.Dispose();
            this.cts.Cancel();
            await receiveTask;
        }