Changes in Serilog 0.2
Thanks for all the feedback on Serilog, keep it coming! Version 0.2 is now on NuGet and introduces a couple of noticeable changes.
Phone and tablet support
The core of Serilog is now portable across .NET 4.5, Windows 8 and Windows Phone 8.
The latter two platforms only include one ‘sink’ out of the box, that writes to a System.IO.TextWriter
. I’d like to set up sinks for local storage on those platforms, if you’re knowledgeable (or brave!) and interested in helping out.
Revised configuration API
The first version of LoggerConfiguration
used flat method chaining to drive the configuration process.
Log.Logger = new LoggerConfiguration()
.MinimumLevel(LogEventLevel.Debug)
.WithConsoleSink()
.CreateLogger();
The number of methods on LoggerConfiguration
became unwieldy quickly. On typing ‘.’, a user would be presented with everything including .WithKitchenSink()
.
0.2 aims at a cleaner IntelliSense experience by grouping options:
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console()
.CreateLogger();
In addition to MinimumLevel
and WriteTo
, you can configure Serilog to Filter
log events based on arbitrary rules, Enrich
log events with properties calculated at runtime, and Destructure
complex parameter types for serialization various ways.
There are advantages and disadvantages to any API, for the moment I’m happy with this direction but open to suggestions (give it a try!) Thanks @droyad, @uglybugger and @turtlator for the motivation and first round of feedback.
Control over ‘destructuring’
The new version survives the serialization of circular object graphs and offers more control over the serialization process. For example, only a selection of properties from HttpRequestMessage
might be included in a log event:
Log.Logger = new LoggerConfiguration()
.Destructure.ByTransforming(
m => new { Uri = m.RequestUri.AbsoluteUri,
m.Method,
m.Headers })
...
Log.Debug("Received {@Message}", httpRequestMessage);
Thanks @sandcastle_hq for putting the momentum behind this.
(Quick note on terminology, Serilog breaks down objects in two phases; destructuring controls the tree created out of regular .NET objects, while serialization is specific to the sink being used, for example converting that tree structure into JSON.)
What’s next?
Use, feedback, documentation, performance profiling and tuning, more sinks.