Skip to content

Instantly share code, notes, and snippets.

@nblumhardt
Created October 28, 2016 06:09
Show Gist options
  • Save nblumhardt/b109ce84f54f1c1daad8df9fae49ed0c to your computer and use it in GitHub Desktop.
Save nblumhardt/b109ce84f54f1c1daad8df9fae49ed0c to your computer and use it in GitHub Desktop.
Shows how to stream events matching a filter in Seq 3.4+ back out through the console via Serilog
Install-Package Seq.Api -Pre
Install-Package Serilog.Formatting.Compact.Reader -Pre
Install-Package Serilog.Sinks.Literate
Install-Package System.Reactive
using Newtonsoft.Json.Linq;
using Seq.Api;
using Serilog;
using Serilog.Formatting.Compact.Reader;
using System;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
namespace SeqStreamingExample
{
class Program
{
static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.LiterateConsole()
.CreateLogger();
Task.Run(Run).Wait();
}
static async Task Run()
{
var connection = new SeqConnection("http://localhost:5341");
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;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment