Seq.Extensions.Logging 8.0.1-dev-00124

This is a prerelease version of Seq.Extensions.Logging.
dotnet add package Seq.Extensions.Logging --version 8.0.1-dev-00124                
NuGet\Install-Package Seq.Extensions.Logging -Version 8.0.1-dev-00124                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Seq.Extensions.Logging" Version="8.0.1-dev-00124" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Seq.Extensions.Logging --version 8.0.1-dev-00124                
#r "nuget: Seq.Extensions.Logging, 8.0.1-dev-00124"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Seq.Extensions.Logging as a Cake Addin
#addin nuget:?package=Seq.Extensions.Logging&version=8.0.1-dev-00124&prerelease

// Install Seq.Extensions.Logging as a Cake Tool
#tool nuget:?package=Seq.Extensions.Logging&version=8.0.1-dev-00124&prerelease                

Seq.Extensions.Logging Build status NuGet Pre Release

Seq is a flexible self-hosted back-end for the ASP.NET Core logging subsystem (Microsoft.Extensions.Logging). Log events generated by the framework and application code are sent over HTTP to a Seq server, where the structured data associated with each event is used for powerful filtering, correlation, and analysis.

For an example, see the dotnetconf deep dive session.

Screenshot

This package makes it a one-liner to configure ASP.NET Core logging with Seq.

Getting started

The instructions that follow are for .NET 6.0+ web applications.

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

dotnet add package Seq.Extensions.Logging

In Program.cs, call AddSeq() on the host's ILoggingBuilder.

// Use the Seq logging configuration in appsettings.json
builder.Host.ConfigureLogging(loggingBuilder =>
    loggingBuilder.AddSeq());

The framework will inject 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:

Property Value
Message "The current values are 3 and 5"
Fizz 3
Buzz 5

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.

Parameter Description Example value
apiKey A Seq API key to authenticate or tag messages from the logger "1234567890"
levelOverrides A dictionary mapping logger name prefixes to minimum logging levels new Dictionary<string,LogLevel>{ ["Microsoft"] = LogLevel.Warning }
minimumLevel The level below which events will be suppressed (the default is Information) LogLevel.Trace

JSON configuration

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

In appsettings.json add a "Seq" property to "Logging" to configure the server URL, API key, and levels for the Seq provider:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information"
    },
    "Seq": {
      "ServerUrl": "http://localhost:5341",
      "ApiKey": "1234567890",
      "LogLevel": {
        "System": "Information",
        "Microsoft": "Warning"
      }
    }
  }
}

Dynamic log level control

The logging provider will dynamically adjust the default logging level up or down based on the level associated with an API key in Seq. For further information see the Seq documentation.

Including literal JSON strings in log events

The logging provider ships with a JsonSafeString type that can be used to communicate to the logger that a string contains valid JSON, which can be safely included in a log event as structured data.

var json = "{\"A\": 42}";
_logger.LogInformation("The answer is {Answer}", new JsonSafeString(json));

Trace and span correlation

The Seq logger provider automatically adds trace and span ids to events when present, enabling the Trace drop-down menu in Seq's expanded event view.

ASP.NET Core may add additional top-level TraceId, SpanId, and ParentId properties in its default configuration. You can remove these if you wish, using ILoggingBuilder.Configure():

builder.Logging.Configure(opts => {
    opts.ActivityTrackingOptions = ActivityTrackingOptions.None;
});

Enrichment

You can add additional structured data to events being sent to Seq by specifying enricher callbacks in the AddSeq() method:

    .AddSeq(enrichers: [evt => evt.AddOrUpdateProperty(
        "ThreadId",
        Environment.CurrentManagedThreadId)
    ]))

Troubleshooting

Nothing showed up, what can I do?

If events don't appear in Seq after pressing the refresh button in the filter bar, either your application was unable to contact the Seq server, or else the Seq server rejected the log events for some reason.

Server-side issues

The Seq server may reject incoming events if they're missing a required API key, if the payload is corrupted somehow, or if the log events are too large to accept.

Server-side issues are diagnosed using the Seq Ingestion Log, which shows the details of any problems detected on the server side. The ingestion log is linked from the Settings > Diagnostics page in the Seq user interface.

Client-side issues

If there's no information in the ingestion log, the application was probably unable to reach the server because of network configuration or connectivity issues. These are reported to the application through SelfLog.

Add the following line after the logger is configured to print any error information to the console:

Seq.Extensions.Logging.SelfLog.Enable(Console.Error);

If the console is not available, you can pass a delegate into SelfLog.Enable() that will be called with each error message:

Seq.Extensions.Logging.SelfLog.Enable(message => {
    // Do something with `message`
});
Troubleshooting checklist
  • Check the Seq Ingestion Log, as described in the Server-side issues section above.
  • Turn on the SelfLog as described above to check for connectivity problems and other issues on the client side.
  • Raise an issue, ask for help on the Seq support forum or email support@datalust.co.

Versioning policy

The major version of this package tracks the major version of its Microsoft.Extensions.Logging dependency. So, if your application (on any target runtime) is targeting net6.0, use the latest 6.* version of this package. Likewise, if you're targeting net8.0, target a 8.* version of Seq.Extensions.Logging for the best experience.

Credits

This package is based on a subset of the powerful Serilog library. Not all of the options supported by the Serilog and Seq client libraries are present in the Seq.Extensions.Logging package.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (18)

Showing the top 5 NuGet packages that depend on Seq.Extensions.Logging:

Package Downloads
FenixAlliance.ACL.Dependencies

Application Component for the Alliance Business Suite.

GR.Logger

Package Description

ITgenerator.Web

Package Description

Itgenerator.SharedLibrary

Package Description

CodeGame.HostingStartup

Package Description

GitHub repositories (5)

Showing the top 5 popular GitHub repositories that depend on Seq.Extensions.Logging:

Repository Stars
Mimetis/Dotmim.Sync
A brand new database synchronization framework, multi platform, multi databases, developed on top of .Net Standard 2.0. https://dotmimsync.readthedocs.io/
andrewlock/asp-dot-net-core-in-action-2e
Source code examples for ASP.NET Core in Action, Second Edition
andrewlock/asp-dot-net-core-in-action
Source code examples for ASP.NET Core in Action
andrewlock/asp-dot-net-core-in-action-3e
Source code examples for ASP.NET Core in Action, Third Edition
v0l/void.cat
Free file hosting website
Version Downloads Last updated
8.0.1-dev-00124 811 8/21/2024
8.0.1-dev-00123 119 8/21/2024
8.0.1-dev-00119 141 8/19/2024
8.0.0 602,243 1/28/2024
8.0.0-dev-00115 99 1/28/2024
8.0.0-dev-00113 101 1/28/2024
6.1.0 2,022,148 8/9/2022
6.1.0-dev-00103 209 8/8/2022
6.1.0-dev-00091 10,909 4/27/2021
6.0.2-dev-00090 281 4/27/2021
6.0.0 1,954,832 1/12/2021
6.0.0-dev-00086 382 1/7/2021
5.0.0 33,182 1/6/2021
5.0.0-dev-00080 339 1/6/2021
5.0.0-dev-00067 6,892 11/26/2019
4.0.2 384,210 11/24/2019
4.0.2-dev-00060 458 11/24/2019
4.0.1 404,442 3/15/2019
4.0.1-dev-00056 509 3/15/2019
4.0.0 303,505 8/24/2017
4.0.0-dev-00050 866 8/23/2017
3.0.0 4,430 8/18/2017
3.0.0-dev-00044 811 8/18/2017
3.0.0-dev-00042 827 8/18/2017
2.1.3 4,225 6/27/2017
2.1.3-dev-00037 858 6/27/2017
2.1.2 3,597 2/15/2017
2.1.2-dev-00033 914 2/15/2017
2.1.2-dev-00031 972 12/2/2016
2.1.1 2,141 11/16/2016
2.1.1-dev-00027 849 11/15/2016
2.1.0 1,067 11/14/2016
2.1.0-dev-00022 845 11/13/2016
2.0.1 1,425 11/4/2016
2.0.1-dev-00017 1,181 11/4/2016
2.0.0 1,176 10/14/2016
2.0.0-dev-00013 849 10/14/2016
2.0.0-dev-00012 871 10/14/2016
1.0.1 1,118 10/4/2016
1.0.0 2,448 9/30/2016
1.0.0-dev-00006 892 10/4/2016
1.0.0-dev-00003 859 9/30/2016