Persistent logs and traces for .NET Aspire

This post continues on from a previous post, Enhancing .NET Aspire Observability with Seq. Since that post was published, a Seq component has been included in .NET Aspire, making it even easier to include Seq in your .NET Aspire solution.

The built-in Aspire dashboard provides a way to browse logs, traces and metrics, however, it does not have a persistent data store. Each time the Aspire solution restarts all logs, traces and metrics disappear.

Using Seq as your Aspire logs and traces dashboard allows you to keep your logs and traces for as long as you like and manage your storage using Seq's retention policies. It also means you can use Seq's other features, like analytical queries, dashboards and alerts.

Getting Started

To begin, add the Aspire.Seq package to your Aspire projects:

dotnet add package Aspire.Seq

Example Usage

In the Program.cs file of your component-consuming project, call the AddSeqEndpoint extension to configure your project to send logs and traces to Seq (as well as the .NET Aspire dashboard).


AppHost Usage

In your app host project, install the Aspire.Hosting.Seq NuGet package.

dotnet add package Aspire.Hosting.Seq

Then register a Seq server and add it as a reference to your other projects:

var seq = builder.AddSeq("seq");


That is all you need to do to have Seq start with your Aspire solution and receive logs and traces from your projects. You will see the same telemetry data in the Aspire dashboard and in Seq. The Aspire dashboard keeps logs and traces separate, but the Seq user interface unifies them into a single view and timeline so that you can work with logs and traces at the same time.

The Seq user interface unifies logs and traces into a single view and timeline.

Persistent Logs and Traces

To retain Seq's data and configuration across application restarts, add a data volume or bind mount when adding the Seq component. This tells the Seq container where to store Seq's data and configuration on the host file system.

A data volume creates persistent storage for the Seq container managed by the container runtime:

var seq = builder.AddSeq("seq")

A data bind mount maps a local directory into the container. Note that the specified directory must already exist:

var seq = builder.AddSeq("seq")

Now when your application stops, the log and trace data is saved to persistent storage and will be available next time the application starts.

If you are developing with .NET Aspire, the Seq component provides an easy way to enhance the telemetry dashboard experience, and to have persistent logs and traces.

Liam McLennan

Read more posts by this author.