Exemple #1
0
        private async Task Should_send_logs_to_udp_syslog_service(IPEndPoint endpoint)
        {
            var syslogFormatter = new Rfc3164Formatter(Facility.Local0, "TestApp");

            var sink = new SyslogUdpSink(endpoint, syslogFormatter);

            // Start a simple UDP syslog server that will capture all received messaged
            var receiver = new UdpSyslogReceiver();

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

            var receiveTask = receiver.StartReceiving(endpoint, this.cts.Token);

            // Generate and send 3 log events
            var logEvents = Some.LogEvents(3);
            await sink.EmitBatchAsync(logEvents);

            // Wait until the server has received all the messages we sent, or the timeout expires
            await this.countdown.WaitAsync(4000, this.cts.Token);

            // The server should have received all 3 messages sent by the sink
            this.messagesReceived.Count.ShouldBe(logEvents.Length);
            this.messagesReceived.ShouldAllBe(x => logEvents.Any(e => x.EndsWith(e.MessageTemplate.Text)));

            sink.Dispose();
            this.cts.Cancel();
            await receiveTask;
        }
Exemple #2
0
        private async Task SendUdpAsync(IPAddress address)
        {
            // Start a simple UDP syslog server that will capture all received messaged
            var receiver = new UdpSyslogReceiver(this.cts.Token);

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

            var syslogFormatter = new Rfc3164Formatter(Facility.Local0, "TestApp");

            var ipEndPoint = new IPEndPoint(address, receiver.ListeningIPEndPoint.Port);

            var sink = new SyslogUdpSink(ipEndPoint, syslogFormatter);

            // Generate and send 3 log events
            var logEvents = Some.LogEvents(NumberOfEventsToSend);
            await sink.EmitBatchAsync(logEvents);

            // Wait until the server has received all the messages we sent, or the timeout expires
            await this.countdown.WaitAsync(TimeoutInSeconds, this.cts.Token);

            // The server should have received all 3 messages sent by the sink
            this.messagesReceived.Count.ShouldBe(logEvents.Length);
            this.messagesReceived.ShouldAllBe(x => logEvents.Any(e => x.EndsWith(e.MessageTemplate.Text)));

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