![]() |
VOOZH | about |
dotnet add package Serilog.Formatting.Compact --version 3.0.0
NuGet\Install-Package Serilog.Formatting.Compact -Version 3.0.0
<PackageReference Include="Serilog.Formatting.Compact" Version="3.0.0" />
<PackageVersion Include="Serilog.Formatting.Compact" Version="3.0.0" />Directory.Packages.props
<PackageReference Include="Serilog.Formatting.Compact" />Project file
paket add Serilog.Formatting.Compact --version 3.0.0
#r "nuget: Serilog.Formatting.Compact, 3.0.0"
#:package Serilog.Formatting.Compact@3.0.0
#addin nuget:?package=Serilog.Formatting.Compact&version=3.0.0Install as a Cake Addin
#tool nuget:?package=Serilog.Formatting.Compact&version=3.0.0Install as a Cake Tool
A simple, compact JSON-based event format for Serilog. CompactJsonFormatter significantly reduces the byte count of small log events when compared with Serilog's default JsonFormatter, while remaining human-readable. It achieves this through shorter built-in property names, a leaner format, and by excluding redundant information.
A simple Hello, {User} event.
{"@t":"2016-06-07T03:44:57.8532799Z","@mt":"Hello, {User}","User":"nblumhardt"}
Install from NuGet:
dotnet add package Serilog.Formatting.Compact
The formatter is used in conjunction with sinks that accept ITextFormatter. For example, the file sink:
Log.Logger = new LoggerConfiguration()
.WriteTo.File(new CompactJsonFormatter(), "./logs/myapp.json")
.CreateLogger();
<appSettings> configurationTo specify the formatter in XML <appSettings> provide its assembly-qualified type name:
<appSettings>
<add key="serilog:using:File" value="Serilog.Sinks.File" />
<add key="serilog:write-to:File.path" value="./logs/myapp.json" />
<add key="serilog:write-to:File.formatter"
value="Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact" />
appsettings.json configurationTo specify formatter in json appsettings.json provide its assembly-qualified type name:
{
"Serilog": {
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "./logs/myapp.json",
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
}
}
]
}
}
CompactJsonFormatter will preserve the message template, properties, and formatting information so that the rendered message can be created at a later point. When the
JSON is intended for consumption in an environment without message template rendering, RenderedCompactJsonFormatter can be used instead.
Instead of the message template, RenderedCompactJsonFormatter writes the fully-rendered message, as well as
an event id generated from the message template, into the event:
{"@t":"2016-06-07T03:44:57.8532799Z","@m":"Hello, \"nblumhardt\"","@i":"7a8b9c0d","User":"nblumhardt"}
The format written by the compact formatters is specified generically so that implementations for other logging libraries, including Microsoft.Extensions.Logging, are possible if desired.
Each event is a JSON object with event data at the top level. Any JSON property on the payload object is assumed to be a regular property of the event, apart from the reified properties below.
The format defines a handful of reified properties that have special meaning:
| Property | Name | Description | Required? |
|---|---|---|---|
@t |
Timestamp | An ISO 8601 timestamp | Yes |
@m |
Message | A fully-rendered message describing the event | |
@mt |
Message Template | Alternative to Message; specifies a message template over the event's properties that provides for rendering into a textual description of the event | |
@l |
Level | An implementation-specific level identifier (string or number) | Absence implies "informational" |
@x |
Exception | A language-dependent error representation potentially including backtrace | |
@i |
Event id | An implementation specific event id (string or number) | |
@r |
Renderings | If @mt includes tokens with programming-language-specific formatting, an array of pre-rendered values for each such token |
May be omitted; if present, the count of renderings must match the count of formatted tokens exactly |
@tr |
Trace id | The id of the trace that was active when the event was created, if any | |
@sp |
Span id | The id of the span that was active when the event was created, if any |
The @ sigil may be escaped at the start of a user property name by doubling, e.g. @@name denotes a property called @name.
When events are batched into a single payload, a newline-delimited stream of JSON documents is required. Either \n or \r\n delimiters may be used. Batches of newline-separated compact JSON events can use the (unofficial) MIME type application/vnd.serilog.clef.
Versioning would be additive only, with no version identifier; implementations should treat any unrecognised reified properties as if they are user data.
The output and benchmarks below compare the compact JSON formatter with Serilog's built-in JsonFormatter.
Event
Log.Information("Hello, {@User}, {N:x8} at {Now}",
new
{
Name = "nblumhardt",
Tags = new[] { 1, 2, 3 }
},
123,
DateTime.Now);
Default JsonFormatter 292 bytes
{"Timestamp":"2016-06-07T13:44:57.8532799+10:00","Level":"Information","MessageT
emplate":"Hello, {@User}, {N:x8} at {Now}","Properties":{"User":{"Name":"nblumha
rdt","Tags":[1,2,3]},"N":123,"Now":"2016-06-07T13:44:57.8532799+10:00"},"Renderi
ngs":{"N":[{"Format":"x8","Rendering":"0000007b"}]}}
CompactJsonFormatter 187 bytes (0.64)
{"@t":"2016-06-07T03:44:57.8532799Z","@mt":"Hello, {@User}, {N:x8} at {Now}","@r
":["0000007b"],"User":{"Name":"nblumhardt","Tags":[1,2,3]},"N":123,"Now":2016-06
-07T13:44:57.8532799+10:00}
Formatting benchmark
See test/Serilog.Formatting.Compact.Tests/FormattingBenchmarks.cs.
| Formatter | Median | StdDev | Scaled |
|---|---|---|---|
JsonFormatter |
11.2775 µs | 0.0682 µs | 1.00 |
CompactJsonFormatter |
6.0315 µs | 0.0429 µs | 0.53 |
JsonFormatter(renderMessage: true) |
13.7585 µs | 0.1194 µs | 1.22 |
RenderedCompactJsonFormatter |
7.0680 µs | 0.0605 µs | 0.63 |
Several tools are available for working with the CLEF format.
clef-tool - a CLI application for processing CLEF filesseqcli - pretty-print CLEF files at the command-line, or ingest CLEF files into Seq for search, and analysisLogEventsSerilog.Formatting.Compact is not intended to provide customizable formatters. See this blog post for comprehensive Serilog JSON output customization examples.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 is compatible. net463 net463 was computed. net47 net47 was computed. net471 net471 is compatible. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Serilog.Formatting.Compact:
| Package | Downloads |
|---|---|
|
Serilog.AspNetCore
Serilog support for ASP.NET Core logging |
|
|
Serilog.Sinks.Elasticsearch
Serilog sink for Elasticsearch |
|
|
Serilog.Extensions.Logging.File
Add file logging to ASP.NET Core apps with one line of code. |
|
|
Umbraco.Cms.Web.Common
Contains the web assembly needed to run Umbraco CMS. |
|
|
Umbraco.Cms.Infrastructure
Contains the infrastructure assembly needed to run Umbraco CMS. |
Showing the top 20 popular GitHub repositories that depend on Serilog.Formatting.Compact:
| Repository | Stars |
|---|---|
|
dotnet/yarp
A toolkit for developing high-performance HTTP reverse proxy applications.
|
|
|
kurrent-io/KurrentDB
KurrentDB is a database that's engineered for modern software applications and event-driven architectures. Its event-native design simplifies data modeling and preserves data integrity while the integrated streaming engine solves distributed messaging challenges and ensures data consistency.
|
|
|
umbraco/Umbraco-CMS
Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
|
|
|
BililiveRecorder/BililiveRecorder
录播姬 | mikufans 生放送录制
|
|
|
rnwood/smtp4dev
smtp4dev - the fake smtp email server for development and testing
|
|
|
nuke-build/nuke
🏗 The AKEless Build System for C#/.NET
|
|
|
fullstackhero/blazor-starter-kit
Clean Architecture Template for Blazor WebAssembly Built with MudBlazor Components.
|
|
|
ChangemakerStudios/Papercut-SMTP
Papercut SMTP -- The Simple Desktop Email Server
|
|
|
Belphemur/SoundSwitch
C# application to switch default playing device. Download: https://soundswitch.aaflalo.me/
|
|
|
kgrzybek/sample-dotnet-core-cqrs-api
Sample .NET Core REST API CQRS implementation with raw SQL and DDD using Clean Architecture.
|
|
|
ErsatzTV/legacy
Open-source platform that transforms your personal media library into live, custom TV channels.
|
|
|
exceptionless/Exceptionless
Exceptionless application
|
|
|
microsoft/kernel-memory
Research project. A Memory solution for users, teams, and applications.
|
|
|
chocolatey/ChocolateyGUI
A delicious GUI for Chocolatey
|
|
|
serilog/serilog-aspnetcore
Serilog integration for ASP.NET Core
|
|
|
saucepleez/taskt
taskt (pronounced 'tasked' and formely sharpRPA) is free and open-source robotic process automation (rpa) built in C# powered by the .NET Framework
|
|
|
CXWorld/CapFrameX
Frametime capture and analysis tool
|
|
|
dotnet/crank
Benchmarking infrastructure for applications
|
|
|
DragoQCC/CrucibleC2
A C# Command & Control framework
|
|
|
Soluto/kamus
An open source, git-ops, zero-trust secret encryption and decryption solution for Kubernetes applications
|
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0 | 139,240,305 | 6/9/2024 |
| 3.0.0-dev-00980 | 708 | 6/9/2024 |
| 2.0.1-dev-00969 | 36,090 | 2/5/2024 |
| 2.0.0 | 182,178,569 | 11/9/2023 |
| 2.0.0-dev-00962 | 1,096 | 11/9/2023 |
| 2.0.0-dev-00961 | 148,163 | 10/4/2023 |
| 1.1.1-dev-00944 | 626,928 | 5/11/2021 |
| 1.1.1-dev-00940 | 150,312 | 3/6/2020 |
| 1.1.1-dev-00939 | 7,736 | 3/6/2020 |
| 1.1.0 | 399,747,702 | 10/17/2019 |
| 1.1.0-dev-00934 | 1,968 | 10/17/2019 |
| 1.0.1-dev-00933 | 10,198 | 10/6/2019 |
| 1.0.1-dev-00929 | 2,115 | 10/5/2019 |
| 1.0.1-dev-00925 | 108,413 | 1/24/2019 |
| 1.0.1-dev-00922 | 371,456 | 10/23/2016 |
| 1.0.1-dev-00920 | 3,526 | 8/29/2016 |
| 1.0.0 | 156,756,567 | 7/5/2016 |
| 1.0.0-rc-916 | 2,733 | 6/26/2016 |
| 1.0.0-rc-915 | 2,616 | 6/26/2016 |
| 1.0.0-rc-912 | 2,700 | 6/25/2016 |