Example #1
0
        /// <summary>
        /// Adds a sink that writes log events as to a Splunk instance via UDP.
        /// </summary>
        /// <param name="loggerConfiguration">The logger config</param>
        /// <param name="connectionInfo"></param>
        /// <param name="formatter">Custom formatter to use if you e.g. do not want to use the JsonFormatter.</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <returns></returns>
        public static LoggerConfiguration SplunkViaUdp(
            this LoggerSinkConfiguration loggerConfiguration,
            SplunkUdpSinkConnectionInfo connectionInfo,
            ITextFormatter formatter,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)
        {
            var sink = new UdpSink(connectionInfo, formatter);

            return(loggerConfiguration.Sink(sink, restrictedToMinimumLevel));
        }
Example #2
0
        /// <summary>
        /// Adds a sink that writes log events as to a Splunk instance via UDP.
        /// </summary>
        /// <param name="loggerConfiguration">The logger config</param>
        /// <param name="connectionInfo"></param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <param name="renderTemplate">If true, the message template is rendered</param>
        /// <returns></returns>
        public static LoggerConfiguration SplunkViaUdp(
            this LoggerSinkConfiguration loggerConfiguration,
            SplunkUdpSinkConnectionInfo connectionInfo,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            IFormatProvider formatProvider         = null,
            bool renderTemplate = true)
        {
            var sink = new UdpSink(connectionInfo, formatProvider, renderTemplate);

            return(loggerConfiguration.Sink(sink, restrictedToMinimumLevel));
        }
Example #3
0
        private void ConfigureSerilog()
        {
            var splunkConnectionInfo =
                new SplunkUdpSinkConnectionInfo(hostname: _settings.SplunkHost, port: _settings.SplunkUdpPort);

            var configuration = new LoggerConfiguration()
                                .MinimumLevel.Is(_settings.GlobalMinimumLogLevel)
                                .WriteTo.Console(
                outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message,-30:lj} {Properties:j}{NewLine}{Exception}",
                theme: AnsiConsoleTheme.Literate)
                                .WriteTo.Trace()
                                //.WriteTo.SplunkViaUdp(splunkConnectionInfo, restrictedToMinimumLevel: _settings.SplunkMinimumLogLevel)
                                .WriteTo.SplunkViaUdp(IPAddress.Loopback, 1515, LogEventLevel.Information)
                                .Enrich.FromLogContext();

            if (!string.IsNullOrEmpty(_settings.SeqUrl))
            {
                configuration.WriteTo.Seq(_settings.SeqUrl);
            }

            _logger = configuration.CreateLogger();
        }