Skip to content

A Resilient and durable Serilog sink that writes events to the Splunk

License

Notifications You must be signed in to change notification settings

alirezavafi/serilog-sinks-splunk-durable

 
 

Repository files navigation

Serilog.Sinks.Splunk.Durable NuGet

A Resilient and durable Serilog sink that writes events to the Splunk (based on Seq sink https://datalust.co/seq). Supports .NET 4.5+, .NET Core, and platforms compatible with the .NET Platform Standard 1.1 including Windows 8 & UWP, Windows Phone and Xamarin.

Getting started

Install the Serilog.Sinks.Splunk.Durable package from Visual Studio's NuGet console:

PM> Install-Package Serilog.Sinks.Splunk.Durable

Point the logger to Splunk Event Collector:

Log.Logger = new LoggerConfiguration()
                     .WriteTo
                     .SplunkEventCollector(splunkHost: "http://localhost:8088",
                                           eventCollectorToken: "1e3fa824-6c86-4e14-a1de-ce87d1bb5dd8",
                                           bufferFileFullName: "Test.log")    
                     .CreateLogger();

And use the Serilog logging methods to associate named properties with log events:

Log.Error("Failed to log on user {ContactId}", contactId);

JSON appsettings.json configuration

To use the Splunk.Plus sink with Microsoft.Extensions.Configuration, for example with ASP.NET Core or .NET Core, use the Serilog.Settings.Configuration package. First install that package if you have not already done so:

Install-Package Serilog.Settings.Configuration

Instead of configuring the sink directly in code, call ReadFrom.Configuration():

var configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .Build();

var logger = new LoggerConfiguration()
    .ReadFrom.Configuration(configuration)
    .CreateLogger();

In your appsettings.json file, under the Serilog node, :

{
  "Serilog": {
    "Using": [ "Serilog.Sinks.Splunk.Durable" ],
    "WriteTo": [
       {
        "Name": "SplunkEventCollector",
        "Args": {
          "splunkHost": "http://localhost:8088",
          "eventCollectorToken": "1e3fa824-6c86-4e14-a1de-ce87d1bb5dd8",
          "bufferFileFullName": "log-buffer.txt"
        }
      }
    ]
  }
}

See the XML <appSettings> example above for a discussion of available Args options.

About

A Resilient and durable Serilog sink that writes events to the Splunk

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 98.2%
  • PowerShell 1.8%