Alexaka1.Serilog.Extensions.Formatting
0.4.2
See the version list below for details.
dotnet add package Alexaka1.Serilog.Extensions.Formatting --version 0.4.2
NuGet\Install-Package Alexaka1.Serilog.Extensions.Formatting -Version 0.4.2
<PackageReference Include="Alexaka1.Serilog.Extensions.Formatting" Version="0.4.2" />
<PackageVersion Include="Alexaka1.Serilog.Extensions.Formatting" Version="0.4.2" />
<PackageReference Include="Alexaka1.Serilog.Extensions.Formatting" />
paket add Alexaka1.Serilog.Extensions.Formatting --version 0.4.2
#r "nuget: Alexaka1.Serilog.Extensions.Formatting, 0.4.2"
#:package Alexaka1.Serilog.Extensions.Formatting@0.4.2
#addin nuget:?package=Alexaka1.Serilog.Extensions.Formatting&version=0.4.2
#tool nuget:?package=Alexaka1.Serilog.Extensions.Formatting&version=0.4.2
Alexaka1.Serilog.Extensions.Formatting
Utf8JsonFormatter
A simple JSON formatter for Serilog that uses the System.Text.Json.Utf8JsonWriter
to write the log events to the output stream. As the name suggests, it is entirely built around UTF-8, with all the .NET optimizations for UTF-8, so using other encodings will most likely result in invalid characters. The default for the File sink is UTF-8.
Usage
var logger = new LoggerConfiguration()
.WriteTo.File(new Utf8JsonFormatter(), "log.json")
.CreateLogger();
{
"Name": "Console",
"Args": {
"formatter": {
"type": "Serilog.Extensions.Formatting.Utf8JsonFormatter, Serilog.Extensions.Formatting",
// if you want to use a custom naming policy, you can specify it here
"namingPolicy": "System.Text.Json.JsonNamingPolicy::CamelCase, System.Text.Json"
}
}
}
Options
The Utf8JsonFormatter
constructor accepts the following options:
closingDelimiter
: Closing delimiter of the log event. Defaults toEnvironment.NewLine
.renderMessage
: A boolean that determines whether the message template will be rendered. Defaults tofalse
.formatProvider
: AnIFormatProvider
that will be used to format the message template. Defaults toCultureInfo.InvariantCulture
.spanBufferSize
: The size of the buffer used to format theISpanFormattable
values. Defaults to64
.skipValidation
: A boolean that determines whether the JSON writer will skip validation. Defaults totrue
.namingPolicy
: AJsonNamingPolicy
that will be used to convert the property names. Default is leaving the property names as they are.jsonWriterEncoder
: AJavaScriptEncoder
that will be used to encode the JSON output. Defaults tonull
which is considered to be safe. However please note that some Unicode characters will be escaped in the output. More info.
Why?
I specifically had a use-case in a project which required logs to be in camelCase
, and none of the built-in formatters supported that, not even ExpressionTemplate
, since I couldn't find a way to specify a custom JsonNamingPolicy
for properties.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Serilog (>= 4.0.1)
- System.Text.Json (>= 8.0.4)
-
net6.0
- Serilog (>= 4.0.1)
-
net8.0
- Serilog (>= 4.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.