Ejemplo n.º 1
0
        public async Task Extension_method_config_with_port_and_Rfc5424_format_and_messageIdPropertyName()
        {
            var receiver = new UdpSyslogReceiver(this.cts.Token);

            var logger = new LoggerConfiguration();

            logger.WriteTo.UdpSyslog(IPAddress.Loopback.ToString(),
                                     receiver.ListeningIPEndPoint.Port,
                                     format: SyslogFormat.RFC5424,
                                     messageIdPropertyName: "WidgetProcess");

            var evtProperties = new List <LogEventProperty>
            {
                new LogEventProperty("WidgetProcess", new ScalarValue("Widget42")),
            };

            // Should produce log events like:
            // <134>1 2013-12-19T00:01:00.000000-07:00 DSGCH0FP72 testhost.net462.x86 2396 Widget42 [meta WidgetProcess="Widget42"] __2
            var logEvents = Some.LogEvents(NumberOfEventsToSend, evtProperties);

            await TestLoggerFromExtensionMethod(logger, receiver, altLogEvents : logEvents);
        }
        public async Task Should_timeout_when_attempting_secure_tcp_to_non_secure_syslog_service()
        {
            // This is all that is needed for the client to attempt to initiate a TLS connection.
            this.tcpConfig.SecureProtocols = SECURE_PROTOCOLS;

            // As for the server, note that we aren't passing in the server certificate and we're
            // instructing it to just listen and read and ignore any data.
            var receiver = new TcpSyslogReceiver(null, SECURE_PROTOCOLS, this.cts.Token, true);

            this.tcpConfig.Host = IPAddress.Loopback.ToString();
            this.tcpConfig.Port = receiver.IPEndPoint.Port;
            this.tcpConfig.TlsAuthenticationTimeout = TimeSpan.FromSeconds(5);

            var sink = new SyslogTcpSink(this.tcpConfig);

            var logEvents = Some.LogEvents(3);

            await Assert.ThrowsAsync <OperationCanceledException>(async() => await sink.EmitBatchAsync(logEvents));

            sink.Dispose();
            this.cts.Cancel();
        }
Ejemplo n.º 3
0
        private async Task TestLoggerFromExtensionMethod(LoggerConfiguration logger, UdpSyslogReceiver receiver, int expected = NumberOfEventsToSend, Events.LogEvent[] altLogEvents = null)
        {
            receiver.MessageReceived += (_, msg) =>
            {
                this.messagesReceived.Add(msg);
                this.countdown.Signal();
            };

            var log = logger.CreateLogger();

            var logEvents = altLogEvents ?? Some.LogEvents(NumberOfEventsToSend);

            foreach (var item in logEvents)
            {
                log.Write(item);
            }

            log.Dispose();

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

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

            if (altLogEvents != null)
            {
                var source = altLogEvents.First().Properties.Keys.First();

                this.messagesReceived.ShouldAllBe(x => logEvents.Any(e => x.Contains(source)));
            }

            this.cts.Cancel();
        }