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; }
public async Task Should_send_logs_to_udp_syslog_service() { var syslogFormatter = new Rfc3164Formatter(Facility.Local0, "TestApp"); var sink = new SyslogUdpSink(this.endpoint, syslogFormatter, this.batchConfig); var log = GetLogger(sink); var receiver = new UdpSyslogReceiver(); receiver.MessageReceived += (_, msg) => { this.messagesReceived.Add(msg); this.countdown.Signal(); }; var receiveTask = receiver.StartReceiving(this.endpoint, 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); 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; }