Monday, July 4, 2016

Validating message templates using SerilogAnalyzer

A few years ago, I switched my logging framework of choice to Serilog, a structured logging framework.

To use structured logging, you use a concept called ‘message templates’. The are a simple DSL extending .NET form strings. It looks a little bit like string interpolation, but with more power.

A quick example copied from the Serilog website:

The stored message will be a combination of the message template with the placeholders and the properties captured in JSON format:

The only problem is that similar to string.format and  in contrast to string interpolation, the compiler doesn’t give any warnings when the provided message template is incorrect or any of the parameters is missing.

Time to introduce SerilogAnalyzer, a Roslyn-based analysis for code using the Serilog logging library. It checks for common mistakes and usages problems.

A must have if you are using Serilog today! Download the Visual Studio Extension here: https://github.com/Suchiman/SerilogAnalyzer/releases

SerilogAnalyzer

No comments: