Struct Redactor.RedactedValue<T>
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
TThe 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
redactorRedactorThe redactor that redacts it.
valueTThe value, or null.
redactFunc<Redactor, T, string>The redaction.
Methods
ToString()
Redacts the value now.
public override string ToString()
Returns
- string
The redacted text, or
<null>.