Serilog.Formatting.Compact.Reader 3.0.0-dev-00063

Serilog.Formatting.Compact.Reader Build status NuGet Pre Release

This package reads (deserializes) JSON log files created by Serilog.Formatting.Compact back into Serilog LogEvents.

Example

Log events are written to a file using CompactJsonFormatter:

using (var fileLog = new LoggerConfiguration()
    .WriteTo.File(new CompactJsonFormatter(), "log.clef")
    .CreateLogger())
{
    fileLog.Information("Hello, {@User}", new { Name = "nblumhardt", Id = 101 });
    fileLog.Information("Number {N:x8}", 42);
    fileLog.Warning("Tags are {Tags}", new[] { "test", "orange" });

    try
    {
        throw new DivideByZeroException();
    }
    catch(Exception ex)
    {
        fileLog.Error(ex, "Something failed");
    }
}

This creates a log file with content similar to:

{"@t":"2016-10-12T04:46:58.0554314Z","@mt":"Hello, {@User}","User":{"Name":"nblumhardt","Id":101}}
{"@t":"2016-10-12T04:46:58.0684369Z","@mt":"Number {N:x8}","@r":["0000002a"],"N":42}
{"@t":"2016-10-12T04:46:58.0724384Z","@mt":"Tags are {Tags}","@l":"Warning","Tags":["test","orange"]}
{"@t":"2016-10-12T04:46:58.0904378Z","@mt":"Something failed","@l":"Error", "@x":"System.DivideByZer...<snip>"}

An instance of LogEventReader converts each line of the log file back into a LogEvent, which can be manipulated, rendered, or written through another Serilog sink:

using (var console = new LoggerConfiguration()
    .WriteTo.LiterateConsole()
    .CreateLogger())
{
    using (var clef = File.OpenText("log.clef"))
    {
        var reader = new LogEventReader(clef);
        LogEvent evt;
        while (reader.TryRead(out evt))
            console.Write(evt);
    }
}

Output from the logger:

Screenshot

Limitations

Events deserialized from JSON are for typical purposes just like the original log events. There are two main things to keep in mind:

  1. JSON doesn't carry all of the type information necessary to determine if, for example, a number is an int or a float. JSON.NET does a good job of deserializing anything that it encounters, but you can't rely on the types here being identical.
  2. Exceptions deserialized this way aren't instances of the original exception type - all you can do with them is call ToString() to get the formatted message and stack trace, which is what 99% of Serilog sinks will do.

Showing the top 20 packages that depend on Serilog.Formatting.Compact.Reader.

Packages Downloads
Nuke.Build
Cross-platform build automation system Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit '46bbe7900f7f6426f377c713dd11d76e37516bc3' (see contained AppVeyorSettings.json file for build settings).
19
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit '011956b31c05f14f3233f6241cd6fbe038824d71' (see contained AppVeyorSettings.json file for build settings).
25
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit '1688d821b6cef6e19f869ca665d7b0ba4c33255a' (see contained AppVeyorSettings.json file for build settings).
19
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit '245ccadae9fc856bef1b7c929958e3230fd1f729' (see contained AppVeyorSettings.json file for build settings).
17
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit '369ef2b8fd696c639b333812edf5c5fdd5f3e7e6' (see contained AppVeyorSettings.json file for build settings).
17
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit '7d7354dfb4a5e2983fbb8924faa922954169be2e' (see contained AppVeyorSettings.json file for build settings).
16
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit '9ced2aa3a6cecfbea5ef45d692ef7f156da0dbe0' (see contained AppVeyorSettings.json file for build settings).
17
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit 'a94fbe2ca0c12a4bf2df0a4c92e9dc51ee8f1076' (see contained AppVeyorSettings.json file for build settings).
15
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit 'aeacff85068cb9218354491b39fbf916e5ea28e8' (see contained AppVeyorSettings.json file for build settings).
22
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit 'b8bba6eef97ac1c59c954464983ce7b9080240e6' (see contained AppVeyorSettings.json file for build settings).
15
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit 'bbceff250ec4c9c604b33b38600ab9b4a4e17dac' (see contained AppVeyorSettings.json file for build settings).
21
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit 'cda28e5941e47b2b2a3d9bea20f78d11af1d92e0' (see contained AppVeyorSettings.json file for build settings).
22
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit 'd8ff60a63e8e7bb77b64c9820c42add96835772d' (see contained AppVeyorSettings.json file for build settings).
21
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit 'e782a00085e84e022c341a265b54c0c9308cbe78' (see contained AppVeyorSettings.json file for build settings).
22
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit 'ea86450b4db1568563b15122f0250495fd55776e' (see contained AppVeyorSettings.json file for build settings).
16
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit 'f38745a72c2c9d9f630ffd2fe5e04431ce2d166f' (see contained AppVeyorSettings.json file for build settings).
16
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit 'f6123b1450735fa0fc6dd2713b40f23019f470b1' (see contained AppVeyorSettings.json file for build settings).
21
Nuke.Common
Cross-platform build automation system Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit '1b7919295cb9cac9eccc00871c6d1b8bc1bed375' (see contained AppVeyorSettings.json file for build settings).
26
Nuke.Common
Cross-platform build automation system Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit '39132f3fb1fea9f889894dfe520cf4434d6eca4e' (see contained AppVeyorSettings.json file for build settings).
24
Nuke.Common
Cross-platform build automation system Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit 'fa8aae50ade3b7479a059fcd775fd4dc1a108220' (see contained AppVeyorSettings.json file for build settings).
20

.NET Framework 4.6.2

.NET Standard 2.1

.NET Standard 2.0

.NET 7.0

.NET 6.0

.NET 5.0

.NET Framework 4.7.1

Version Downloads Last updated
4.1.0-dev-00085 17 12/05/2024
4.1.0-dev-00082 14 11/24/2024
4.0.1-dev-00081 12 12/12/2024
4.0.1-dev-00079 14 12/10/2024
4.0.0 20 11/29/2024
4.0.0-dev-00071 15 11/24/2024
3.0.0 21 05/06/2024
3.0.0-dev-00063 15 12/06/2024
2.0.0 23 05/12/2024
2.0.0-dev-00060 30 05/08/2024
1.0.6-dev-00059 13 12/03/2024
1.0.5 24 05/09/2024
1.0.5-dev-00048 21 05/12/2024
1.0.4 16 11/14/2024
1.0.3 17 11/24/2024
1.0.3-dev-00036 22 05/15/2024
1.0.3-dev-00034 15 11/24/2024
1.0.3-dev-00033 14 12/10/2024
1.0.2 16 11/24/2024
1.0.2-dev-00024 25 05/12/2024
1.0.2-dev-00020 15 11/25/2024
1.0.1 18 05/08/2024
1.0.1-dev-00016 14 11/15/2024
1.0.1-dev-00014 21 11/20/2024
1.0.0 17 12/16/2024
1.0.0-dev-00010 18 05/09/2024
1.0.0-dev-00008 17 11/29/2024
1.0.0-dev-00006 16 11/20/2024
1.0.0-dev-00004 16 11/20/2024
1.0.0-dev-00002 19 05/09/2024
1.0.0-dev-00001 15 11/15/2024