Using Seq in 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.
Install Seq on Windows
Getting started is easy and quick. You need to:
- Download and install the Seq server
- Add the appropriate NuGet package to your application
And that’s it! Here we go step by step.
Installing the Seq Server
The Seq server is a Windows service that accepts incoming events and hosts the main web user interface over HTTP or HTTPS.
If you’re just setting up on your own developer workstation, you machine almost certainly has everything required. If you’re hosting Seq on a shared server for your team, check out the System Requirements and Azure Installation Guide.
Opening the installer MSI file will start the Setup Wizard:
Step through each page of the wizard. On a developer workstation the defaults are fine. Check out the Production Deployment Checklist if you’re going “live”.
After the wizard completes, browse the Seq UI at http://localhost:5341
Getting started
Add the Nuget Package manager to your project :
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);
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"));