public TcpSyslogSinkTests()
 {
     this.tcpConfig = new SyslogTcpConfig
     {
         KeepAlive = true,
         Formatter = new Rfc5424Formatter(Facility.Local0, "TestApp"),
         Framer    = new MessageFramer(FramingType.OCTET_COUNTING)
     };
 }
Esempio n. 2
0
        /// <summary>
        /// Adds a sink that writes log events to a TCP syslog server, optionally over a TLS-secured
        /// channel
        /// </summary>
        /// <param name="loggerSinkConfig">The logger configuration</param>
        /// <param name="config">Defines how to interact with the syslog server</param>
        public static LoggerConfiguration TcpSyslog(this LoggerSinkConfiguration loggerSinkConfig,
                                                    SyslogTcpConfig config)
        {
            if (String.IsNullOrWhiteSpace(config.Host))
            {
                throw new ArgumentException(nameof(config.Host));
            }

            var sink = new SyslogTcpSink(config, BatchConfig.Default);

            return(loggerSinkConfig.Sink(sink));
        }
Esempio n. 3
0
        /// <summary>
        /// Adds a sink that writes log events to a TCP syslog server, optionally over a TLS-secured
        /// channel
        /// </summary>
        /// <param name="loggerSinkConfig">The logger configuration</param>
        /// <param name="config">Defines how to interact with the syslog server</param>
        /// <param name="restrictedToMinimumLevel">The minimum level for events passed through the sink</param>
        public static LoggerConfiguration TcpSyslog(this LoggerSinkConfiguration loggerSinkConfig,
                                                    SyslogTcpConfig config, LogEventLevel restricedToMinimumLevel = LevelAlias.Minimum)
        {
            if (String.IsNullOrWhiteSpace(config.Host))
            {
                throw new ArgumentException(nameof(config.Host));
            }

            var sink = new SyslogTcpSink(config, BatchConfig.Default);

            return(loggerSinkConfig.Sink(sink, restricedToMinimumLevel));
        }
Esempio n. 4
0
        public TcpSyslogSinkTests(ITestOutputHelper output)
        {
            this.tcpConfig = new SyslogTcpConfig
            {
                KeepAlive = true,
                Formatter = new Rfc5424Formatter(Facility.Local0, "TestApp"),
                Framer    = new MessageFramer(FramingType.OCTET_COUNTING)
            };

            // This can be useful to see any logging done by the sink. Especially when there is an exception
            // within the sink (and the sink has to catch and log it of course).
            // Ideally, we would configure this globally, or at least in an xUnit Class Fixture (https://xunit.net/docs/shared-context).
            // But the ITestOutputHelper output is not available there. So instead, this will get enabled
            // and disabled for each test, just in case it is needed.
            //
            // But also note that the Serilog Selflog is itself a global/static instance. With xUnit, unit
            // test classes are run in parallel. So we can't have multiple unit test classes enabling and
            // disabling the Serilog Selflog at the same time. So for any unit test classes that utilize
            // this, we will have to instruct xUnit to run them serially with the [Collection] attribute.
            Serilog.Debugging.SelfLog.Enable(x => { output.WriteLine(x); System.Diagnostics.Debug.WriteLine(x); });
        }
Esempio n. 5
0
        /// <summary>
        /// Adds a sink that writes log events to a TCP syslog server, optionally over a TLS-secured
        /// </summary>
        /// <param name="loggerSinkConfig">The logger configuration</param>
        /// <param name="host">Hostname of the syslog server</param>
        /// <param name="port">Port the syslog server is listening on</param>
        /// <param name="appName">The name of the application. Defaults to the current process name</param>
        /// <param name="framingType">How to frame/delimit syslog messages for the wire</param>
        /// <param name="format">The syslog message format to be used</param>
        /// <param name="facility">The category of the application</param>
        /// <param name="secureProtocols">
        /// SSL/TLS protocols to be used for a secure channel. Set to None for an unsecured connection
        /// </param>
        /// <param name="certProvider">Optionally used to present the syslog server with a client certificate</param>
        /// <param name="certValidationCallback">
        /// Optional callback used to validate the syslog server's certificate. If null, the system default
        /// will be used
        /// </param>
        /// <param name="outputTemplate">A message template describing the output messages
        /// <seealso cref="https://github.com/serilog/serilog/wiki/Formatting-Output"/>
        /// </param>
        public static LoggerConfiguration TcpSyslog(this LoggerSinkConfiguration loggerSinkConfig,
                                                    string host, int port        = 1468, string appName = null, FramingType framingType = FramingType.OCTET_COUNTING,
                                                    SyslogFormat format          = SyslogFormat.RFC5424, Facility facility = Facility.Local0,
                                                    SslProtocols secureProtocols = SslProtocols.Tls12, ICertificateProvider certProvider = null,
                                                    RemoteCertificateValidationCallback certValidationCallback = null,
                                                    string outputTemplate = null)
        {
            var formatter = GetFormatter(format, appName, facility, outputTemplate);

            var config = new SyslogTcpConfig
            {
                Host                   = host,
                Port                   = port,
                Formatter              = formatter,
                Framer                 = new MessageFramer(framingType),
                SecureProtocols        = secureProtocols,
                CertProvider           = certProvider,
                CertValidationCallback = certValidationCallback
            };

            return(TcpSyslog(loggerSinkConfig, config));
        }