public void Configure() { var generalSplunkContext = new global::Splunk.Client.Context(Scheme.Https, "127.0.0.1", 8089); var transmitterArgs = new TransmitterArgs { Source = "Splunk.Sample", SourceType = "Splunk Sample Source" }; const string username = "******"; const string password = "******"; const string splunkIndex = "mysplunktest"; var serilogContext = new SplunkContext( generalSplunkContext, splunkIndex, username, password, null, transmitterArgs); Log.Logger = new LoggerConfiguration() .WriteTo.LiterateConsole() .WriteTo.SplunkViaHttp(serilogContext, 100, TimeSpan.FromSeconds(10)) .Enrich.WithThreadId() .Enrich.WithProperty("SplunkSample", "ViaHttp") .MinimumLevel.Debug() .CreateLogger(); }
/// <summary> /// Adds a sink that writes log events as to a Splunk instance via http. /// </summary> /// <param name="loggerConfiguration">The logger configuration.</param> /// <param name="context">The Splunk context to log to</param> /// <param name="batchInterval"></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="batchSizeLimit"></param> /// <returns>Logger configuration, allowing configuration to continue.</returns> /// <exception cref="ArgumentNullException">A required parameter is null.</exception> /// <remarks>TODO: Add link to splunk configuration and wiki</remarks> public static LoggerConfiguration SplunkViaHttp( this LoggerSinkConfiguration loggerConfiguration, SplunkContext context, int batchSizeLimit, TimeSpan batchInterval, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, IFormatProvider formatProvider = null) { var sink = new SplunkViaHttpSink(context, batchSizeLimit, batchInterval, formatProvider); return(loggerConfiguration.Sink(sink, restrictedToMinimumLevel)); }
/// <summary> /// Adds a sink that writes log events as to a Splunk instance via http. /// </summary> /// <param name="loggerConfiguration">The logger configuration.</param> /// <param name="context">The Splunk context to log to</param> /// <param name="batchSizeLimit">The size of the batch prior to logging</param> /// <param name="batchInterval">The interval on which to log via http</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 will be rendered</param> /// <returns>Logger configuration, allowing configuration to continue.</returns> /// <exception cref="ArgumentNullException">A required parameter is null.</exception> /// <remarks>TODO: Add link to splunk configuration and wiki</remarks> public static LoggerConfiguration SplunkViaHttp( this LoggerSinkConfiguration loggerConfiguration, SplunkContext context, int batchSizeLimit, TimeSpan batchInterval, LogEventLevel restrictedToMinimumLevel = LogEventLevel.Debug, IFormatProvider formatProvider = null, bool renderTemplate = true) { var sink = new SplunkViaHttpSink(context, batchSizeLimit, batchInterval, formatProvider, renderTemplate); return(loggerConfiguration.Sink(sink)); }
static void Main() { ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; //Generally it is not advised to log to Splunk via HTTP/HTTPS due to volume of data //This is available for mobile apps and other special cases. const string host = "127.0.0.1"; //Only used for HTTP/HTTPS scenarios var generalSplunkContext = new Context(Scheme.Https, host, 8089); var transmitterArgs = new TransmitterArgs { Source = "Splunk.Sample", SourceType = "Splunk Sample Source" }; const string username = "******"; const string password = "******"; const string splunkIndex = "mysplunktest"; var serilogContext = new SplunkContext(generalSplunkContext, splunkIndex, username, password, null, transmitterArgs); Log.Logger = new LoggerConfiguration() .Enrich.With(new ThreadIdEnricher()) .Enrich.WithMachineName() .WriteTo.ColoredConsole() .WriteTo.SplunkViaHttp(serilogContext, 10, TimeSpan.FromSeconds(5)) //See http://docs.splunk.com/Documentation/Splunk/6.1.3/Data/Monitornetworkports .WriteTo.SplunkViaUdp(host, 10000) .WriteTo.SplunkViaTcp(host, 10001) .CreateLogger(); var serilogLogger = Log.ForContext <Program>(); serilogLogger.Information("Hello from Serilog, running as {Username}!", Environment.UserName); var items = Enumerable.Range(1, 1000); foreach (var item in items) { serilogLogger.Information("Logging an int, what fun {Item}", item); } Console.WriteLine("OK"); Console.ReadLine(); }