Documentation
DocumentationDiscussions
Documentation
These docs are for v4. Click to read the latest docs for v2024.3.

Using ASP.NET Core

Seq fully-supports the advanced structured logging provided by .NET Core and ASP.NET Core.

This page describes Seq.Extensions.Logging, a provider for Microsoft.Extensions.Logging with simple loggingBuilder.AddSeq() configuration.

👍

If you're writing apps across multiple target platforms, or want more advanced structured logging features, we recommend using Serilog with Seq, which also fully-supports .NET Core and ASP.NET Core.

Getting started

Add the NuGet package to your project either by editing the CSPROJ file, or using the NuGet package manager:

Install-Package Seq.Extensions.Logging

In your Startup class's ConfigureServices() method, call AddSeq() on the loggingBuilder provided by AddLogging().

public void ConfigureServices(IServiceCollection services)
{
    services.AddLogging(loggingBuilder =>
    {
        loggingBuilder.AddSeq();
    });
    // ...

The framework injects ILogger instances into controllers and other classes:

class HomeController : Controller
{
    readonly ILogger<HomeController> _log;
    
    public HomeController(ILogger<HomeController> log)
    {
        _log = log;
    }
    
    public IActionResult Index()
    {
        _log.LogInformation("Hello, world!");
    }
}

Log messages will be sent to Seq in batches and be visible in the Seq user interface. Observe that correlation identifiers added by the framework, like RequestId, are all exposed and fully-searchable in Seq.

Logging with message templates

Seq supports the templated log messages used by Microsoft.Extensions.Logging. By writing events with named format placeholders, the data attached to the event preserves the individual property values.

var fizz = 3, buzz = 5;
log.LogInformation("The current values are {Fizz} and {Buzz}", fizz, buzz);

This records an event like:

PropertyValue
Message"The current values are 3 and 5"
Fizz3
Buzz5

Seq makes these properties searchable without additional log parsing. For example, a filter expression like Fizz < 4 would match the event above.

Additional configuration

The AddSeq() method exposes some basic options for controlling the connection and log volume.

ParameterDescriptionExample value
apiKeyA Seq API key to authenticate or tag messages from the logger"1234567890"
levelOverridesA dictionary mapping logger name prefixes to minimum logging levelsnew Dictionary<string,LogLevel>{ ["Microsoft"] = LogLevel.Warning }
minimumLevelThe level below which events will be suppressed (the default is Information)LogLevel.Trace

JSON configuration

The Seq server URL, API key and other settings can be read from JSON configuration if desired.

In appsettings.json add a "Seq" property:

{
  "Seq": {
    "ServerUrl": "http://localhost:5341",
    "ApiKey": "1234567890",
    "MinimumLevel": "Trace",
    "LevelOverride": {
      "Microsoft": "Warning"
    }
  }
}

And then pass the configuration section to the AddSeq() method:

        loggingBuilder.AddSeq(Configuration.GetSection("Seq"));