CodoMetis.TypeKit.Serilog 2.3.1

Prefix Reserved
dotnet add package CodoMetis.TypeKit.Serilog --version 2.3.1
                    
NuGet\Install-Package CodoMetis.TypeKit.Serilog -Version 2.3.1
                    
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="CodoMetis.TypeKit.Serilog" Version="2.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CodoMetis.TypeKit.Serilog" Version="2.3.1" />
                    
Directory.Packages.props
<PackageReference Include="CodoMetis.TypeKit.Serilog" />
                    
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 CodoMetis.TypeKit.Serilog --version 2.3.1
                    
#r "nuget: CodoMetis.TypeKit.Serilog, 2.3.1"
                    
#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 CodoMetis.TypeKit.Serilog@2.3.1
                    
#: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=CodoMetis.TypeKit.Serilog&version=2.3.1
                    
Install as a Cake Addin
#tool nuget:?package=CodoMetis.TypeKit.Serilog&version=2.3.1
                    
Install as a Cake Tool

CodoMetis.TypeKit.Serilog

Serilog logs your CodoMetis.TypeKit value objects and closed sets as what they print, also where it destructures them. A value object that masks itself stays masked.

dotnet add package CodoMetis.TypeKit.Serilog

It needs Serilog 4.0.0 or later.

using Serilog;

using var logger = new LoggerConfiguration()
    .Destructure.WithTypeKit()
    .WriteTo.Console()
    .CreateLogger();

logger.Information("Created {@Client}", new Client(ApiKey.From("k-123"), "Ann"));   // Created {"Key": "ApiKey(***)", "Name": "Ann", "$type": "Client"}
  • Why you need it. Serilog destructures an object ({@Key}, or a record holding one) by reading its public properties, and a value object's Value is public. Without this package, a value object that masks itself with a hand-written ToString() is logged unmasked there, as { Value: "k-123" }. That is the only place it leaks. With the package, Serilog logs value objects as their text, as Microsoft.Extensions.Logging does.
  • Every value object becomes a string, masked or not. An OrderId is "0199aaaa-...", not { Value: "0199aaaa-..." }, and a Quantity is "3". A list or a dictionary of them becomes a list or a dictionary of strings.
  • A closed set is logged as its name, or as what its own ToString() prints, never by its properties. {@Order} holds Status: "Shipped", not the set's constant data. An instance that the set's own code made beside its members has no name, and Serilog logs that it could not capture it.
  • Nothing to register per type. The package recognises a value object or a closed set by the attribute the generators put on it. So the host needs this package and the base package, not the generators. Serilog handles every other type as before.
  • To mask a value object, write its ToString(). The Generators README says what else still carries the value then.
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
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
2.3.1 421 10/31/2026
2.3.0 408 10/29/2026
2.2.0 745 10/18/2026
2.1.0 1,221 10/15/2026
2.0.0 177 10/14/2026
1.5.1 129 10/11/2026
1.5.0 112 10/11/2026

Changed

- Packages: the public surface is checked against 2.3.0's, so nothing 2.3.0 ships is removed or changed in 2.3.1.
- Analyzers: CMTK0005 and CMTK0006 now warn for a type parameter bound by a value object beside new(), as in where T : IValue<int>, new(), which CMTK0001 already reported: new T[n] and a T field nothing sets. In a build that treats warnings as errors, that can report code that built before (CMTK0005 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.3.1/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0005)).
- Generators: a generated member you wrote where a value object reaches it now fails the build (CMTK1011, CMTK1008 for comparison), so your build can fail when you upgrade: an explicit implementation such as IFormattable.ToString in an interface a value object or closed set implements, one in a base record from another project, a base record's public MinValue or MaxValue, which stood in for the generated one, and a base record's Create beside your own. Remove it, don't implement that interface, or declare the marker on the value object itself. A base record's public Value, Parse, ToString(string?, IFormatProvider?) and the like, and IConvertible through an interface, now fail with a CMTK error rather than a Metalama crash (Write your own members (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.3.1/src/CodoMetis.TypeKit.Generators/README.md#write-your-own-members)).
- Generators: an Equals a value object declares for one of its base records' types, such as Equals(DeepBase?), now fails the build (CMTK1011), so your build can fail when you upgrade. A HashSet<DeepBase> compared by it while == compared the underlying value; normalise values in Create instead (Equality (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.3.1/src/CodoMetis.TypeKit.Generators/README.md#equality)).
- Generators: a CompareTo(TSelf), CompareTo(object), TryFrom or Revalidate a value object inherits from a base record now fails the build (CMTK1008, CMTK1011), so your build can fail when you upgrade. It stood in for the generated member: an inherited CompareTo made < overflow the stack and an EF Core query order by the column, and an inherited TryFrom need not run Create. Declare it on the value object (Write your own members (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.3.1/src/CodoMetis.TypeKit.Generators/README.md#write-your-own-members)).
- Generators: a closed set over a base class that declares a member the generators add now fails the build with CMTK1011 naming it, where it failed with a Metalama error that named nothing you wrote: its Parse, TryParse, Match or All, and an IParsable<TSelf> it implements. A base class's ToString() that isn't sealed now fails the build too (CMTK1011), so your build can fail when you upgrade: the generated ToString() replaced it without a word. Declare ToString() in the set, or seal the base's, which is then kept (Closed sets (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.3.1/src/CodoMetis.TypeKit.Generators/README.md#closed-sets)).
- Generators: IValueObject<TSelf, T>, IValueObjectMaterializer<TSelf, T> or IPlainValueObject<TSelf, T> declared through an interface of yours, such as an IEntityId<TSelf> : IValueObject<TSelf, Guid>, or by a base record now fails with CMTK1011 naming that interface, where it failed with a Metalama error (LAMA0512) that named nothing you wrote. To constrain generic code, use IValueObject<TSelf, T> itself (Write your own members (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.3.1/src/CodoMetis.TypeKit.Generators/README.md#write-your-own-members)).
- EF Core: Min, Max, Order, OrderDescending or OrderBy(x => x) over a value object with its own CompareTo, cast to object first, as in Select(o => (object)o.Priority).Max(), or read back through ??, a member of a projection, a grouping's key, a join or a subquery's First(), as in Select(o => new { Key = (object)o.Priority }).OrderBy(a => a.Key), now throws as the same query without the cast does. EF dropped the cast and answered the column's order, the opposite of memory's for a descending CompareTo (Queries (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.3.1/src/CodoMetis.TypeKit.EntityFrameworkCore/README.md#queries)).
- Analyzers: CMTK0006 now warns when a constructor sets a member only on another object it creates, new Order(...) { Id = id } or other with { Id = id }, which it took as setting its own. In a build that treats warnings as errors, that can report code that built before (CMTK0006 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.3.1/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0006)).
- EF Core: a query filter that orders values your context holds without a lambda, as in HasQueryFilter(o => o.Priority == Limits.Max()), builds again; EF works it out in memory by your CompareTo. With a lambda, EF orders those values in the database, and the filter still fails (Queries (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.3.1/src/CodoMetis.TypeKit.EntityFrameworkCore/README.md#queries)).
- Analyzers: CMTK0005 now also warns at Array.CreateInstance(typeof(OrderId), n), Array.CreateInstanceFromArrayType(typeof(OrderId[]), n) and ArrayPool<OrderId>.Rent(n), which create default slots as new OrderId[n] does. In a build that treats warnings as errors, that can report code that built before (CMTK0005 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.3.1/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0005)).
- Generators: an overload of a generated member that C# tells apart by its type parameters, or by a parameter that is ref, in or out where the generated one's isn't (or the other way round), is now kept beside the generated member, on a value object, a closed set or a base of either, where the build failed with CMTK1011: a Parse<TFormat>(string, IFormatProvider?), a From(in int), a TryParse whose last parameter isn't out (Write your own members (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.3.1/src/CodoMetis.TypeKit.Generators/README.md#write-your-own-members)).
- Generators: a generic ToString<TFormat>(), or a generic or by-in CompareTo(TSelf), is no longer taken for the one you may write: a value object printed what a record prints (Level { Value = 3 }), a closed set its type name, and the ordering was marked hand-written, so EF Core refused to order by it. A generic or by-reference overload of TryFrom, Revalidate, CompareTo(object), Equals, GetHashCode or PrintMembers is kept beside the generated member, where the build failed with CMTK1011 or CMTK1008 (Write your own members (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.3.1/src/CodoMetis.TypeKit.Generators/README.md#write-your-own-members)).
- Generators: a member of a base record or of a closed set's base class that the type can't see, a private one such as a private const int MaxValue, doesn't count as its own: it stands in for no generated member, so the checks above leave it alone and the type is generated as in 2.3.0 (Write your own members (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.3.1/src/CodoMetis.TypeKit.Generators/README.md#write-your-own-members)).

Fixed

- Analyzers: CMTK0005 no longer reports an array with a constant zero in any one dimension, such as new OrderId[0, count], or a zero written as 0L or, in a stackalloc, (byte)0: neither holds an element (CMTK0005 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.3.1/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0005)).
- Analyzers: CMTK0006 no longer reports an explicit interface implementation that every constructor assigns through a cast, ((IHasId)this).Id = id (CMTK0006 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.3.1/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0006)).
- OpenAPI: each element of a list, an array or a dictionary of Patch<T> is described as a patch property is, the argument's schema admitting null, where it admitted anything. A nullable Patch<T>? is its argument's schema admitting null, where it was an empty required component; System.Text.Json reads a null there as a null patch, as it reads a property left out (Use it in an endpoint and in the document (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.3.1/docs/merge-patches.md#use-it-in-an-endpoint-and-in-the-document)).

Full changelog: https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/main/CHANGELOG.md