Created
October 28, 2016 06:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Install-Package Seq.Api -Pre | |
Install-Package Serilog.Formatting.Compact.Reader -Pre | |
Install-Package Serilog.Sinks.Literate | |
Install-Package System.Reactive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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