SeqTraceListener Class

Trace listener that writes to a Writes to a Seq server.


Install via NuGet:


This listener writes to a Seq server, including additional properties as specified in the config file.

For performance, the listener will queue messages and send to the Seq server over HTTP in batches of 100 (default) messages, with a timeout of 1,000 (default) milliseconds; if there is less than a full batch when the timeout is reached, the batch is sent anyway, so low volume messages will be sent every one second.

Both these settings are configurable.

In addition, the first message logged (or the first message after a completed timeout), is sent immediately in a batch (usually a single message). This first message lets the Seq server know the application is up an running without having to wait 1 second for the first batch.

When the HTTP post to send the batch fails, the component includes a retry algorithm. There is a back off delay, based on the batch timeout, that doubles for each retry.

The default maximium number of retries is 10 (about 17 minutes based on the default settings and algorithm). This should be enough to cover small outages and network interruptions.

Additional message that arrive during retry are queued, and then sent (in batches) once the connection is back up. The maximum queue size can also be specified (default 1,000), after which messages are instead dropped (to prevent filling up memory).

If the maximum number of retries is reached, then the failing batch is dropped; this helps overcome if the batch contains a poison message or is the cause of the HTTP failure (rather than it being a network issue).

Config Attributes

Attribute Description
initializeData URL of the Seq server (e.g. local development is usually http://localhost:5341).
traceOutputOptions If specified, sent as additional properties (can be specified either here, or in additionalProperties).
apiKey Your API key for the Seq server (for local development this can be empty).
additionalProperties Additional named properties to include in the Seq message.
batchSize Number of messages per batch, default 100. A batch size of 0 will disable batching and each message is sent as a separate HTTP request, with no retries.
batchTimeout Timeout after which incomplete batches are sent anyway, default 1,000 milliseconds.
maxQueueSize Maximum number of messages to queue; once this limit is reached, messages are dropped. Default is 1,000.
maxRetries Maximum number of retries where transmission to the Seq server fails, e.g. HTTP timeout. Retries have a backoff algorithm that doubles the wait time each attempt; the default is 10 retries, which works out at around 17 minutes. After the specified number of retries the batch is dropped (e.g. if it contains a poison message).

Example Config

<?xml version="1.0" encoding="utf-8" ?>
      <add name="seq" 
        type="Essential.Diagnostics.SeqTraceListener, Essential.Diagnostics.SeqTraceListener" 
        apiKey=" " />
      <source name="ExampleSource" switchValue="All">
          <clear />
          <add name="seq" />

Example Output

Events are sent to the specified Seq server, where they can be queried, filtered, etc.

SeqTraceListener example Seq output

Config Template

<add name="seq"
  type="Essential.Diagnostics.SeqTraceListener, Essential.Diagnostics.SeqTraceListener" 
  initializeData="Seq server URL"
  apiKey="your API key, or blank for localhost"
  batchSize="100|use 0 to disable"

Last edited Feb 8 at 10:15 AM by sgryphon, version 8


No comments yet.