Alexaka1.Serilog.Extensions.Formatting 0.4.2

There is a newer version of this package available.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Alexaka1.Serilog.Extensions.Formatting" Version="0.4.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Alexaka1.Serilog.Extensions.Formatting" Version="0.4.2" />
                    
Directory.Packages.props
<PackageReference Include="Alexaka1.Serilog.Extensions.Formatting" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Alexaka1.Serilog.Extensions.Formatting --version 0.4.2
                    
#r "nuget: Alexaka1.Serilog.Extensions.Formatting, 0.4.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Alexaka1.Serilog.Extensions.Formatting@0.4.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Alexaka1.Serilog.Extensions.Formatting&version=0.4.2
                    
Install as a Cake Addin
#tool nuget:?package=Alexaka1.Serilog.Extensions.Formatting&version=0.4.2
                    
Install as a Cake Tool

Alexaka1.Serilog.Extensions.Formatting

NuGet Version

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 to Environment.NewLine.
  • renderMessage: A boolean that determines whether the message template will be rendered. Defaults to false.
  • formatProvider: An IFormatProvider that will be used to format the message template. Defaults to CultureInfo.InvariantCulture.
  • spanBufferSize: The size of the buffer used to format the ISpanFormattable values. Defaults to 64.
  • skipValidation: A boolean that determines whether the JSON writer will skip validation. Defaults to true.
  • namingPolicy: A JsonNamingPolicy that will be used to convert the property names. Default is leaving the property names as they are.
  • jsonWriterEncoder: A JavaScriptEncoder that will be used to encode the JSON output. Defaults to null 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.0 125 11/18/2024
0.4.3 116 10/10/2024
0.4.2 1,045 9/13/2024
0.4.1 165 8/28/2024
0.4.0 134 8/27/2024