Skip to main content
Version: 0.3.x (0.3.0)

Class ValueObjectLoggerConfigurationExtensions

Namespace: AdCodicem.ValueObjects.Serilog
Assembly: AdCodicem.ValueObjects.Serilog.dll

Wires value objects into Serilog's capture of log event properties.

public static class ValueObjectLoggerConfigurationExtensions

Inheritance​

object ← ValueObjectLoggerConfigurationExtensions

Inherited Members​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Methods​

ValueObjects(LoggerDestructuringConfiguration)​

Destructures value objects as their underlying value.

public static LoggerConfiguration ValueObjects(this LoggerDestructuringConfiguration destructure)

Parameters​

destructure LoggerDestructuringConfiguration

Serilog's destructuring configuration, LoggerConfiguration.Destructure.

Returns​

LoggerConfiguration

The logger configuration, so that calls can be chained.

Remarks​

A value object logged with @, or met inside an object, a collection or a dictionary logged with @, is captured as the scalar its underlying value is, "Qty": 42 rather than "Qty": {"Value": 42}, and Serilog writes it as it writes that type. Every type implementing is captured so, through : a value object written by hand and a construction of a generic value object included, with nothing registered.

Without @, Serilog captures a type it does not know through ToString(), and consults no destructuring policy: {Qty} stays the text "42". captures it as its underlying value too.

Serilog runs destructuring policies in the order they were declared: an application's own destructuring of a value object type, a mask written with Destructure.ByTransforming<T>() included, applies only when it is declared before this call.

ValueObjects(LoggerDestructuringConfiguration, Action<ValueObjectLoggingOptions>)​

Destructures value objects as their underlying value, with the options given.

public static LoggerConfiguration ValueObjects(this LoggerDestructuringConfiguration destructure, Action<ValueObjectLoggingOptions> configure)

Parameters​

destructure LoggerDestructuringConfiguration

Serilog's destructuring configuration, LoggerConfiguration.Destructure.

configure Action<ValueObjectLoggingOptions>

Sets the options.

Returns​

LoggerConfiguration

The logger configuration, so that calls can be chained.

Remarks​

The assemblies of are registered first. With , Serilog then treats every value object the holds as a scalar, which it captures as it is rather than through ToString(), and an enricher replaces each one an event holds, in its properties and in the structures, sequences and dictionaries they hold, with its underlying value.

The registry is read when this method runs. A construction of a generic value object is in it once it was registered by hand, as native AOT asks, or resolved by another integration before the call, and is then made a scalar as any other; one that was not, and a value object written by hand that nothing registered, is captured as its text until the application makes it a scalar, with Destructure.AsScalar<T>(), and the enricher then replaces it too. The enricher runs where this call places it among the enrichers: an enricher added after it, Enrich.FromLogContext() included, adds a value object the enricher no longer sees, written as its text.

Serilog consults its scalar types before any destructuring policy. Without the option, the application should therefore make no value object a scalar, or it is written as its text with @ too. With it, no destructuring of the application's runs for a value object the registry holds, whatever the order of the calls and wherever it is met: a mask written with Destructure.ByTransforming<T>() is lost, and the masked text is what to log. Without it, an application's own destructuring of a value object type applies when it is declared before this call, Serilog running destructuring policies in the order they were declared.