Seq.Api 4.2.2

Client library for the Seq HTTP API.

There is a newer version of this package available.
See the version list below for details.
Install-Package Seq.Api -Version 4.2.2
dotnet add package Seq.Api --version 4.2.2
<PackageReference Include="Seq.Api" Version="4.2.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Seq.Api --version 4.2.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Seq HTTP API Client Build status NuGet Pre Release Join the chat at https://gitter.im/datalust/seq

This library includes:

  • C# representations of the entities exposed by the Seq HTTP API
  • Helper classes for interacting with the API

It's useful for querying events and working with configuration data - everything you can do using the Seq web UI, you can do programmatically via the API.

If you want to write events to Seq, use one of the logging framework clients, such as Serilog.Sinks.Seq or NLog.Targets.Seq instead.

Getting started

Install from NuGet:

Install-Package Seq.Api

Create a SeqConnection with your server URL:

var connection = new SeqConnection("http://localhost:5341");

Navigate the "resource groups" exposed as properties of the connnection:

var installedApps = await connection.Apps.ListAsync();

To authenticate, the SeqConnection constructor accepts an apiKey parameter (make sure the API key permits user-level access) or, if you want to log in with personal credentials you can await connection.Users.Login(username, password).

For a more complete example, see the seq-tail app included in the source.

Creating entities

The Seq API provides a /template resource for each resource group that provides a new instance of the resource with defaults populated. The API client uses this pattern when creating new entities:

var signal = await connection.Signals.TemplateAsync();
signal.Title = "Signal 123";
await connection.Signals.AddAsync(signal);

See the signal-copy app for an example of this pattern in action.

Reading events

Seq internally limits the resources a query is allowed to consume. The query methods on SeqConnection.Events include a status with each result set - a Partial status indicates that further results must be retrieved.

The snippet below demonstrates paging through results to retrieve the complete set.

string lastReadEventId = null;

while(true)
{
  var resultSet = await connection.Events.InSignalAsync(
      filter: "Environment = 'Test'",
      render: true,
      afterId: lastReadEventId);
      
  foreach (var evt in resultSet.Events)
    Console.WriteLine(evt.RenderedMessage);

  if (resultSet.Statistics.Status != ResultSetStatus.Partial)
    break;
    
  lastReadEventId = resultSet.Statistics.LastReadEventId;
}

If the result set is expected to be small, ListAsync() will buffer results and return a complete list:

var resultSet = await connection.Events.ListAsync(
    filter: "Environment = 'Test'",
    render: true,
    count: 1000);
  
foreach (var evt in resultSet)
  Console.WriteLine(evt.RenderedMessage);

All methods that retrieve events require a count. The API client defaults this value to 30 if not specified.

Streaming events

Seq 3.4 provides live streaming of events matching a filter and/or set of signals.

var filter = "@Level = 'Error'";

using (var stream = await connection.Events.StreamAsync<JObject>(filter: filter))
using (stream.Select(jObject => LogEventReader.ReadFromJObject(jObject))
             .Subscribe(evt => Log.Write(evt)))
{
    await stream;
}

The Events.StreamAsync() method returns a hot IObservable&lt;T&gt; over a WebSocket. The observable will keep producing events until either it's disposed, or the server is shut down.

Seq streams the events in compact JSON format, which the Seq API client library can deserialize into JSON.NET JObjects for consumption.

Serilog.Formatting.Compact.Reader provides the LogEventReader class used above to turn these documents back into Serilog LogEvents. Having the events represented in Serilog’s object model means they can be passed back into a logging pipeline, as performed above using Log.Write().

Working with the basic client

The SeqApiClient class implements the low level interactions with the API's entities and links. It's one step up from System.Net.HttpClient - you may be able to use it in cases not supported by the high-level wrapper.

Create a SeqApiClient with your server URL:

var client = new SeqApiClient("http://localhost:5341");

Get the root resource and use it to retrieve one or more of the resource groups:

var root = await client.GetRootAsync();
var events = await client.GetAsync<ResourceGroup>(root, "EventsResources");

(Available resource groups, like Events, Users and so-on, can be seen in the root document's Links collection.)

Use the client to navigate links from entity to entity:

var matched = await client.List<EventEntity>(
  events,
  "Items",
  new Dictionary<string, object>{{"count", 10}, {"render", true}});

foreach (var match in matched)
  Console.WriteLine(matched.RenderedMessage);

Package versioning

This package does not follow the SemVer rule of major version increments for breaking changes. Instead, the package version tracks the Seq version it supports.

Seq HTTP API Client Build status NuGet Pre Release Join the chat at https://gitter.im/datalust/seq

This library includes:

  • C# representations of the entities exposed by the Seq HTTP API
  • Helper classes for interacting with the API

It's useful for querying events and working with configuration data - everything you can do using the Seq web UI, you can do programmatically via the API.

If you want to write events to Seq, use one of the logging framework clients, such as Serilog.Sinks.Seq or NLog.Targets.Seq instead.

Getting started

Install from NuGet:

Install-Package Seq.Api

Create a SeqConnection with your server URL:

var connection = new SeqConnection("http://localhost:5341");

Navigate the "resource groups" exposed as properties of the connnection:

var installedApps = await connection.Apps.ListAsync();

To authenticate, the SeqConnection constructor accepts an apiKey parameter (make sure the API key permits user-level access) or, if you want to log in with personal credentials you can await connection.Users.Login(username, password).

For a more complete example, see the seq-tail app included in the source.

Creating entities

The Seq API provides a /template resource for each resource group that provides a new instance of the resource with defaults populated. The API client uses this pattern when creating new entities:

var signal = await connection.Signals.TemplateAsync();
signal.Title = "Signal 123";
await connection.Signals.AddAsync(signal);

See the signal-copy app for an example of this pattern in action.

Reading events

Seq internally limits the resources a query is allowed to consume. The query methods on SeqConnection.Events include a status with each result set - a Partial status indicates that further results must be retrieved.

The snippet below demonstrates paging through results to retrieve the complete set.

string lastReadEventId = null;

while(true)
{
  var resultSet = await connection.Events.InSignalAsync(
      filter: "Environment = 'Test'",
      render: true,
      afterId: lastReadEventId);
      
  foreach (var evt in resultSet.Events)
    Console.WriteLine(evt.RenderedMessage);

  if (resultSet.Statistics.Status != ResultSetStatus.Partial)
    break;
    
  lastReadEventId = resultSet.Statistics.LastReadEventId;
}

If the result set is expected to be small, ListAsync() will buffer results and return a complete list:

var resultSet = await connection.Events.ListAsync(
    filter: "Environment = 'Test'",
    render: true,
    count: 1000);
  
foreach (var evt in resultSet)
  Console.WriteLine(evt.RenderedMessage);

All methods that retrieve events require a count. The API client defaults this value to 30 if not specified.

Streaming events

Seq 3.4 provides live streaming of events matching a filter and/or set of signals.

var filter = "@Level = 'Error'";

using (var stream = await connection.Events.StreamAsync<JObject>(filter: filter))
using (stream.Select(jObject => LogEventReader.ReadFromJObject(jObject))
             .Subscribe(evt => Log.Write(evt)))
{
    await stream;
}

The Events.StreamAsync() method returns a hot IObservable&lt;T&gt; over a WebSocket. The observable will keep producing events until either it's disposed, or the server is shut down.

Seq streams the events in compact JSON format, which the Seq API client library can deserialize into JSON.NET JObjects for consumption.

Serilog.Formatting.Compact.Reader provides the LogEventReader class used above to turn these documents back into Serilog LogEvents. Having the events represented in Serilog’s object model means they can be passed back into a logging pipeline, as performed above using Log.Write().

Working with the basic client

The SeqApiClient class implements the low level interactions with the API's entities and links. It's one step up from System.Net.HttpClient - you may be able to use it in cases not supported by the high-level wrapper.

Create a SeqApiClient with your server URL:

var client = new SeqApiClient("http://localhost:5341");

Get the root resource and use it to retrieve one or more of the resource groups:

var root = await client.GetRootAsync();
var events = await client.GetAsync<ResourceGroup>(root, "EventsResources");

(Available resource groups, like Events, Users and so-on, can be seen in the root document's Links collection.)

Use the client to navigate links from entity to entity:

var matched = await client.List<EventEntity>(
  events,
  "Items",
  new Dictionary<string, object>{{"count", 10}, {"render", true}});

foreach (var match in matched)
  Console.WriteLine(matched.RenderedMessage);

Package versioning

This package does not follow the SemVer rule of major version increments for breaking changes. Instead, the package version tracks the Seq version it supports.

Showing the top 1 GitHub repositories that depend on Seq.Api:

Repository Stars
NethermindEth/nethermind
.NET Core Ethereum client for Linux, Windows, MacOs - full and actively developed

Version History

Version Downloads Last updated
5.1.0 2,652 3/21/2019
5.1.0-dev-00094 77 3/21/2019
5.0.0 3,837 11/5/2018
5.0.0-dev-00088 130 10/29/2018
5.0.0-dev-00086 128 10/18/2018
5.0.0-dev-00084 333 5/17/2018
5.0.0-dev-00082 308 4/21/2018
5.0.0-dev-00079 194 4/17/2018
4.2.3-dev-00076 251 2/19/2018
4.2.2 13,611 1/16/2018
4.2.2-dev-00072 227 1/16/2018
4.2.1 261 1/16/2018
4.2.1-dev-00069 272 1/16/2018
4.2.1-dev-00066 209 1/15/2018
4.2.1-dev-00064 228 1/15/2018
4.2.0 397 1/15/2018
4.2.0-dev-00062 263 1/15/2018
4.2.0-dev-00059 225 1/10/2018
4.2.0-dev-00057 228 12/7/2017
4.0.0 28,095 5/16/2017
4.0.0-dev-00047 277 4/28/2017
4.0.0-dev-00045 269 4/25/2017
4.0.0-dev-00042 293 4/16/2017
4.0.0-dev-00041 238 4/16/2017
3.4.3 7,140 2/7/2017
3.4.3-dev-00035 242 1/29/2017
3.4.3-dev-00033 240 1/27/2017
3.4.3-dev-00031 251 1/23/2017
3.4.2 836 12/14/2016
3.4.2-dev-00027 250 12/14/2016
3.4.1 1,853 11/29/2016
3.4.1-dev-00023 237 11/29/2016
3.4.1-dev-00020 257 11/18/2016
3.4.0 296 11/18/2016
3.4.0-dev-00017 268 11/18/2016
3.4.0-dev-00016 268 10/31/2016
3.4.0-dev-00014 268 10/28/2016
3.4.0-dev-00012 239 10/28/2016
3.4.0-dev-00010 259 10/28/2016
3.4.0-dev-00008 254 10/28/2016
3.4.0-dev-00006 254 10/27/2016
3.4.0-dev-00003 247 10/27/2016
3.3.1 918 8/29/2016
3.0.3 588 3/14/2016
2.1.38 458 1/17/2016
2.1.36 283 1/8/2016
2.1.33 332 12/21/2015
2.1.32 358 11/14/2015
2.1.31 292 11/14/2015
2.1.30 399 9/10/2015
2.1.29 313 9/10/2015
2.1.28 393 7/27/2015
2.0.27 292 7/27/2015
2.0.26 293 7/27/2015
2.0.25 298 7/27/2015
2.0.24 292 7/24/2015
2.0.23 299 7/24/2015
2.0.22 350 6/16/2015
2.0.21 322 6/10/2015
0.6.19 370 3/10/2015
0.6.18 337 1/20/2015
0.6.17 321 1/19/2015
0.6.16 384 12/16/2014
0.6.14 370 12/15/2014
0.6.13 320 12/15/2014
0.6.12 326 12/15/2014
0.6.11 324 12/15/2014
0.6.10 367 12/15/2014
0.6.9 371 12/13/2014
0.6.8 324 12/11/2014
0.1.0 340 12/11/2014
Show less