As I explained in the last posts, log messages are not just strings but have an inner meaning. When we use Serilog to write structured log messages we make them explicit to query them later. The tool we want to use to search for a specific orderId
should give us this capability without the need to write all the code from scratch. We therefore need a tool that understands log messages and, if possible, even Serilog. One such tool is Seq that I explain in this blog post.
This post is part of the Improve Your Log Messages series. You can find the other parts here:
- Part 1: The Missed Opportunities of Log Files
- Part 2: Structured Logging with Serilog
- Part 3: RavenDB as a Sink for Serilog
- Part 4: Seq as a Sink for Serilog
- Part 5: How to Influence the Output of Serilog
- Part 6: Monitor your Application with Seq
- Part 7: Debugging Serilog
- Part 8: Elasticsearch as a Sink for Serilog
- Part 9: Monitor your Applications with Kibana
- Part 10: Closing the Feedback Loop from Log Messages to Knowledge
- Part 11: How To Analyse IIS Log Files
- Part 12: Using Logstash to Analyse IIS Log Files with Kibana
- Part 13: Analysing Apache Log Files with Logstash and Kibana
- Part 14: How to Analyse SharePoint Log Files
Installing Seq
Seq is a commercial tool that will cost you 70$ for 5 users per year. However, you can download a free single-user version to find out if Seq is worth the effort. To start you get the installer from GetSeq.net, answer a few questions and click next till you reach the end:
When the installation is completed your browser will open http://localhost:5341/ and point you to the web interface of your freshly installed Seq server. So far you can’t see much, but when the messages arrive this screen will let you look deep into your application. Let’s create some log messages.
Using Seq as Sink
To use Seq with Serilog you need to install the NuGet package Seq.Client.Serilog
Serilog.Sinks.Seq
:
If you prefer the command line you can insert this command in the package console to get the same package installed:
1 |
PM> Install-Package Serilog.Sinks.Seq |
Configure the Sink
When the client is installed you can configure Serilog to use Seq as a sink. This is even simpler as the RavenDB configuration, then Seq only needs the URL your browser opened after the installation:
1 2 3 4 5 |
// Create Logger Log.Logger = new LoggerConfiguration() .WriteTo.Console() .WriteTo.Seq("http://localhost:5341") .CreateLogger(); |
When you run your application the log message is written to Seq and will appear after a few seconds in the web interface:
Search your Messages
The event screen in the web interface offers you an overview on all the received events. If you click on one message it will expand and you will find a green checkmark (include) and a red cross (exclude) to filter your messages. When you want to find all the messages related to orderId 123 you only have to click on the checkmark. Seq will create a query string with orderId == 123
and shows you only the messages that satisfy this condition:
If you want to find another order Id you simply modify this query string. When you need a certain type of entry you can use the context menu of the type field and get all those messages. All you need is to click on some properties and Seq will create filters for your condition.
Next
Before we can fully see the benefits of Seq we have to look a bit deeper into Serilog and how we can manipulate the messages it creates. Depending on how you write your calls to the logger the messages will contain more or less useful data. Next week I will show you how @
and $
can influence the usefulness of a log entry.
Update on 2014/10/11: Add new package name Serilog.Sinks.Seq.
Seq is not free :'(