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 '4667694d0480c8fc8fcc027d7dab8566d3f4dfcd' (see contained AppVeyorSettings.json file for build settings).
40
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).
46
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).
48
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).
24
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).
27
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).
51
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit '45063fd8e8531a3146ee64c9d93f1d3360062c29' (see contained AppVeyorSettings.json file for build settings).
23
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).
23
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).
25
Nuke.Build
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit 'a20c3b752d0c9f533a6e2c21fee6325032cd3d70' (see contained AppVeyorSettings.json file for build settings).
20
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).
38
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).
44
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).
56
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).
43
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).
25
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).
48
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).
43
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).
40
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).
50
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).
45

.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 34 08/18/2024
4.1.0-dev-00082 37 07/22/2024
4.0.1-dev-00081 39 07/22/2024
4.0.1-dev-00079 45 07/22/2024
4.0.0 50 07/22/2024
4.0.0-dev-00071 45 07/22/2024
3.0.0 45 07/22/2024
3.0.0-dev-00063 37 07/22/2024
2.0.0 41 07/22/2024
2.0.0-dev-00060 38 07/22/2024
1.0.6-dev-00059 41 07/22/2024
1.0.5 43 07/22/2024
1.0.5-dev-00048 42 07/22/2024
1.0.4 42 07/22/2024
1.0.3 48 07/22/2024
1.0.3-dev-00036 36 07/22/2024
1.0.3-dev-00034 29 07/22/2024
1.0.3-dev-00033 39 07/22/2024
1.0.2 41 07/22/2024
1.0.2-dev-00024 53 07/22/2024
1.0.2-dev-00020 46 07/22/2024
1.0.1 45 07/22/2024
1.0.1-dev-00016 40 07/22/2024
1.0.1-dev-00014 41 07/22/2024
1.0.0 48 07/22/2024
1.0.0-dev-00010 53 07/22/2024
1.0.0-dev-00008 42 07/22/2024
1.0.0-dev-00006 42 07/22/2024
1.0.0-dev-00004 43 07/22/2024
1.0.0-dev-00002 34 07/22/2024
1.0.0-dev-00001 37 07/22/2024