Class Redactor
Redacts identifying values for logs and screens: a globally routable address becomes a keyed token that cannot be turned back without the process's key, which dies with it; a private or local address stays readable, and host names and IDs keep some of their characters.
Whether redaction applies is carried by the instance, not by the method you pick, so a call site states its own guarantee. Always redacts whatever the settings say — the app UI and the tracking log need that, since neither should start printing real addresses because logging was switched out of anonymous mode.
Redact* produces a string now; Format* wraps the same work in a Redactor.RedactedValue<T>
that redacts on its ToString, which a logger calls when it writes the record.
public class Redactor
- Inheritance
-
Redactor
- Inherited Members
Constructors
Redactor(bool)
Redacts identifying values for logs and screens: a globally routable address becomes a keyed token that cannot be turned back without the process's key, which dies with it; a private or local address stays readable, and host names and IDs keep some of their characters.
Whether redaction applies is carried by the instance, not by the method you pick, so a call site states its own guarantee. Always redacts whatever the settings say — the app UI and the tracking log need that, since neither should start printing real addresses because logging was switched out of anonymous mode.
Redact* produces a string now; Format* wraps the same work in a Redactor.RedactedValue<T>
that redacts on its ToString, which a logger calls when it writes the record.
public Redactor(bool isAnonymousMode)
Parameters
isAnonymousModeboolWhether the instance redacts; otherwise, it writes the values as they are.
Properties
Always
Redacts unconditionally, for callers whose output must never depend on a logging setting.
public static Redactor Always { get; }
Property Value
IsAnonymousMode
Gets a value indicating whether this redactor redacts; otherwise, it writes the values as they are.
public bool IsAnonymousMode { get; }
Property Value
Methods
Format(IEnumerable<IPAddress>)
Wraps addresses for a log line; it redacts on its ToString.
public Redactor.RedactedValue<IReadOnlyList<IPAddress>> Format(IEnumerable<IPAddress> ipAddresses)
Parameters
ipAddressesIEnumerable<IPAddress>The value.
Returns
- Redactor.RedactedValue<IReadOnlyList<IPAddress>>
The wrapped value.
Format(IEnumerable<IpNetwork>)
Wraps networks for a log line; it redacts on its ToString.
public Redactor.RedactedValue<IReadOnlyList<IpNetwork>> Format(IEnumerable<IpNetwork> ipNetworks)
Parameters
ipNetworksIEnumerable<IpNetwork>The value.
Returns
- Redactor.RedactedValue<IReadOnlyList<IpNetwork>>
The wrapped value.
Format(EndPoint?)
Wraps an endpoint for a log line; it redacts on its ToString.
public Redactor.RedactedValue<EndPoint> Format(EndPoint? endPoint)
Parameters
Returns
- Redactor.RedactedValue<EndPoint>
The wrapped value.
Format(IPAddress?)
Wraps an address for a log line; it redacts on its ToString.
public Redactor.RedactedValue<IPAddress> Format(IPAddress? ipAddress)
Parameters
Returns
- Redactor.RedactedValue<IPAddress>
The wrapped value.
Format(IpEndPointValue?)
Wraps an endpoint for a log line; it redacts on its ToString.
public Redactor.RedactedValue<EndPoint> Format(IpEndPointValue? endPoint)
Parameters
endPointIpEndPointValue?The value, or null.
Returns
- Redactor.RedactedValue<EndPoint>
The wrapped value.
Format(IpNetwork?)
Wraps a network for a log line; it redacts on its ToString.
public Redactor.RedactedValue<IpNetwork> Format(IpNetwork? ipNetwork)
Parameters
Returns
- Redactor.RedactedValue<IpNetwork>
The wrapped value.
RedactEndPoint(EndPoint)
Redacts an endpoint's address as RedactIpAddress(IPAddress) does, and keeps its port.
public string RedactEndPoint(EndPoint endPoint)
Parameters
endPointEndPointThe endpoint; one that is not an IP endpoint is written as it is.
Returns
- string
The text.
RedactHostName(string?)
Redacts a host name: one that is an address or an endpoint as one; otherwise, in anonymous mode, all but its first two and last four characters, for a short name all but its last four, and a name of four characters or fewer whole.
public string RedactHostName(string? dnsName)
Parameters
Returns
- string
The text, or
<null>.
RedactId(object?)
Redacts an ID: in anonymous mode, only its second half shows, after **.
public string RedactId(object? id)
Parameters
Returns
- string
The text, or
<null>.
RedactIpAddress(IPAddress)
Redacts an address: a globally routable address becomes a keyed token, the same for the same address within the run; a private or local one stays as it is.
public string RedactIpAddress(IPAddress ipAddress)
Parameters
ipAddressIPAddressThe address.
Returns
- string
The text.
RedactIpAddresses(IReadOnlyList<IPAddress>)
Redacts addresses, separated by commas.
public string RedactIpAddresses(IReadOnlyList<IPAddress> ipAddresses)
Parameters
ipAddressesIReadOnlyList<IPAddress>The addresses.
Returns
- string
The text.
RedactIpNetwork(IpNetwork)
Redacts a network's prefix as RedactIpAddress(IPAddress) does, and keeps its length.
public string RedactIpNetwork(IpNetwork ipNetwork)
Parameters
ipNetworkIpNetworkThe network.
Returns
- string
The text.
RedactIpNetworks(IReadOnlyList<IpNetwork>)
Redacts networks, separated by commas.
public string RedactIpNetworks(IReadOnlyList<IpNetwork> ipNetworks)
Parameters
ipNetworksIReadOnlyList<IpNetwork>The networks.
Returns
- string
The text.
RedactPacketText(string)
Redacts the addresses in a packet's text, after each of its SourceAddress, DestinationAddress,
Src and Dst labels, as RedactIpAddress(IPAddress) does. A value ends at a comma, a space or the
text's end; one that is no address is written as ***, and the rest of the text stays as it is.
public string RedactPacketText(string ipPacketText)
Parameters
ipPacketTextstringThe packet's text.
Returns
- string
The text.