Serilog.Formatting.Compact.Reader 3.0.0

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
Umbraco.Cms.Infrastructure
Contains the infrastructure assembly needed to run Umbraco CMS.
16
Umbraco.Cms.Infrastructure
Contains the infrastructure assembly needed to run Umbraco CMS.
15
Umbraco.Cms.Persistence.EFCore.SqlServer
Adds support for Entity Framework Core SQL Server migrations to Umbraco CMS.
14
Umbraco.Cms.Infrastructure
Contains the infrastructure assembly needed to run Umbraco CMS.
13
Umbraco.Cms.PublishedCache.NuCache
Contains the published cache assembly needed to run Umbraco CMS.
13
Umbraco.Cms.Persistence.SqlServer
Adds support for SQL Server to Umbraco CMS.
13
Umbraco.Cms.Infrastructure
Contains the infrastructure assembly needed to run Umbraco Cms. This package only contains the assembly, and can be used for package development. Use the template in the Umbraco.Templates package to setup Umbraco
12

.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.0.0 17 02/18/2025
3.0.0 12 02/18/2025
2.0.0 14 07/12/2023
1.0.5 13 07/12/2023
1.0.4 15 02/18/2025
1.0.3 15 02/18/2025
1.0.2 16 02/18/2025
1.0.1 13 02/18/2025
1.0.0 14 02/18/2025