billpratt / serilog-sinks-sumologic

A Serilog event sink that writes to Sumo Logic
Apache License 2.0
10 stars 8 forks source link
aspnet aspnet-core serilog serilog-sink sink sumo-logic

Serilog.Sinks.SumoLogic

NuGet NuGet

A Serilog sink that writes events to Sumo Logic.

Package - Serilog.Sinks.SumoLogic | Platforms - .NET 4.5, .NET Core, .NETStandard 1.5

Usage

Basic

// basic usage writes to Sumo Logic with the default source name 'Serilog'
var log = new LoggerConfiguration()
    .WriteTo.SumoLogic("[YOUR SUMO COLLECTOR URL]")
    .CreateLogger();

// override default Sumo Logic source name
var log = new LoggerConfiguration()
    .WriteTo.SumoLogic("[YOUR SUMO COLLECTOR URL]", "FancyPantsSourceName")
    .CreateLogger();

ASP.NET Core

Install-Package Serilog.Extensions.Logging -DependencyVersion Highest
using Serilog;
using Serilog.Sinks.SumoLogic;

public class Startup
{
  public Startup(IHostingEnvironment env)
  {
    Log.Logger = new LoggerConfiguration()
      .WriteTo.SumoLogic("http://localhost")  //replace with your SumoLogic endpoint
      .CreateLogger();

    // Other startup code
public void Configure(IApplicationBuilder app,
                        IHostingEnvironment env,
                        ILoggerFactory loggerfactory,
                        IApplicationLifetime appLifetime)
  {
      loggerfactory.AddSerilog();

      // Ensure any buffered events are sent at shutdown
      appLifetime.ApplicationStopped.Register(Log.CloseAndFlush);