Lewati ke konten
Docs Try Aspire
Docs Try

Connect to Seq

Konten ini belum tersedia dalam bahasa Anda.

Seq logo

This page describes how consuming apps connect to a Seq resource that’s already modeled in your AppHost. For the AppHost API surface — adding a Seq resource, data volumes, EULA acceptance, and endpoints — see Seq hosting integration.

When you reference a Seq resource from your AppHost, Aspire injects the connection information into the consuming app as environment variables. Your app can either read those environment variables directly — the pattern works the same from any language — or, in C#, use the Aspire.Seq client integration for automatic OpenTelemetry log and trace export.

Aspire exposes each property as an environment variable named [RESOURCE]_[PROPERTY]. For instance, the Uri property of a resource called seq becomes SEQ_URI.

The Seq resource exposes the following connection properties:

Property NameDescription
HostThe hostname or IP address of the Seq server
PortThe port number the Seq server is listening on
UriThe connection URI, with the format http://{Host}:{Port}

Example connection string:

Uri: http://localhost:5341

Pick the language your consuming app is written in. Each example assumes your AppHost adds a Seq resource named seq and references it from the consuming app.

For C# apps, the recommended approach is the Aspire.Seq client integration. It registers OpenTelemetry Protocol (OTLP) exporters through dependency injection so that logs and traces are automatically forwarded to Seq. If you’d rather read environment variables directly, see the Read environment variables section at the end of this tab.

Install the 📦 Aspire.Seq NuGet package in the client-consuming project:

.NET CLI — Add Aspire.Seq package
dotnet add package Aspire.Seq

In Program.cs, call AddSeqEndpoint on your IHostApplicationBuilder to register OTLP exporters that send logs and traces to Seq:

C# — Program.cs
builder.AddSeqEndpoint(connectionName: "seq");

The Aspire.Seq client integration offers multiple ways to provide configuration.

Configuration providers. The client integration supports Microsoft.Extensions.Configuration. It loads SeqSettings from appsettings.json (or any other configuration source) by using the Aspire:Seq key:

JSON — appsettings.json
{
"Aspire": {
"Seq": {
"DisableHealthChecks": false,
"ServerUrl": "http://localhost:5341"
}
}
}

Named configuration. When connecting to multiple Seq instances, use named keys under Aspire:Seq:

JSON — appsettings.json
{
"Aspire": {
"Seq": {
"seq1": {
"ServerUrl": "http://seq1:5341",
"DisableHealthChecks": true
},
"seq2": {
"ServerUrl": "http://seq2:5341",
"DisableHealthChecks": false
}
}
}
}

Then register each instance by its connection name:

C# — Program.cs
builder.AddSeqEndpoint("seq1");
builder.AddSeqEndpoint("seq2");

Inline delegates. Pass an Action<SeqSettings> to configure settings inline:

C# — Program.cs
builder.AddSeqEndpoint("seq", static settings =>
{
settings.DisableHealthChecks = true;
settings.ServerUrl = "http://localhost:5341";
});

By default, Aspire client integrations enable health checks. The Aspire.Seq integration adds a health check that attempts to connect to the Seq server’s /health endpoint when DisableHealthChecks is false. The health check is wired into the /health HTTP endpoint, where all registered health checks must pass before the app is considered ready to accept traffic.

Because Seq is a telemetry sink, the Aspire.Seq integration does not emit tracing activities or metrics of its own. It configures the following log category:

Logging categories:

  • Seq

If you prefer not to use the Aspire client integration, you can read the Aspire-injected URI directly from the environment and configure the OpenTelemetry OTLP exporter manually:

C# — Program.cs
using OpenTelemetry.Logs;
using OpenTelemetry.Trace;
var seqUri = Environment.GetEnvironmentVariable("SEQ_URI");
builder.Logging.AddOpenTelemetry(logging =>
{
logging.AddOtlpExporter(otlp => otlp.Endpoint = new Uri($"{seqUri}/ingest/otlp/v1/logs"));
});
builder.Services.AddOpenTelemetry()
.WithTracing(tracing =>
{
tracing.AddOtlpExporter(otlp => otlp.Endpoint = new Uri($"{seqUri}/ingest/otlp/v1/traces"));
});