Table of Contents

Struct Redactor.RedactedValue<T>

Namespace
VpnHood.Net.Toolkit.Utils
Assembly
VpnHood.Net.Toolkit.dll

Carries a value into a log record without redacting it yet.

A log argument is an ordinary method argument, so VhLogger.Format(x) runs before the logger is ever asked whether the level is enabled. Returning a string there means every disabled hot-path statement still pays for the redaction — an allocation, and since the redaction became keyed, an HMAC. This type defers that work to ToString(), which a logger calls when it writes the record; any other call to it redacts too.

The point is that no call site has to remember anything. Guarding hot statements with a level check works too, but it is a ritual that the next log statement someone adds will not repeat.

public readonly struct Redactor.RedactedValue<T> where T : class

Type Parameters

T

The type of the value.

Inherited Members

Constructors

RedactedValue(Redactor, T?, Func<Redactor, T, string>)

Carries a value into a log record without redacting it yet.

A log argument is an ordinary method argument, so VhLogger.Format(x) runs before the logger is ever asked whether the level is enabled. Returning a string there means every disabled hot-path statement still pays for the redaction — an allocation, and since the redaction became keyed, an HMAC. This type defers that work to ToString(), which a logger calls when it writes the record; any other call to it redacts too.

The point is that no call site has to remember anything. Guarding hot statements with a level check works too, but it is a ritual that the next log statement someone adds will not repeat.

public RedactedValue(Redactor redactor, T? value, Func<Redactor, T, string> redact)

Parameters

redactor Redactor

The redactor that redacts it.

value T

The value, or null.

redact Func<Redactor, T, string>

The redaction.

Methods

ToString()

Redacts the value now.

public override string ToString()

Returns

string

The redacted text, or <null>.