Class VhLogger
Provides the process's one log, and the formatting that keeps identifying values out of it.
public static class VhLogger
- Inheritance
-
VhLogger
- Inherited Members
Remarks
Its sinks are providers, added once by whoever owns them, before anything logs: an app's console, a service's system
log, a file. MinLogLevel is the log's own filter, read at each line, so no sink is rebuilt when the app's
log settings change it; a sink may refuse more. Redaction applies to the values passed through the Format
methods, not to messages.
Properties
Instance
Gets the process's logger, the same object for the process's life.
public static ILogger Instance { get; }
Property Value
IsAnonymousMode
Gets or sets a value indicating whether Format redacts identifying values: addresses, endpoints, networks,
IDs and host names. The default is true.
public static bool IsAnonymousMode { get; set; }
Property Value
MinLogLevel
Gets or sets the lowest level the log writes. The default is Information.
public static LogLevel MinLogLevel { get; set; }
Property Value
Redactor
The redactor this logger applies to the values passed through Format. Set only through
IsAnonymousMode, so that turning redaction off stays a single deliberate switch
rather than something any caller can install. Callers that must redact whatever the logging
settings say use Always instead of this one.
public static Redactor Redactor { get; }
Property Value
TcpCloseEventId
Gets or sets the event ID of the Debug line LogError(EventId, Exception, string, params object?[]) writes for a socket's ordinary close.
public static EventId TcpCloseEventId { get; set; }
Property Value
Methods
AddProvider(ILoggerProvider)
Adds a sink to the log.
public static void AddProvider(ILoggerProvider loggerProvider)
Parameters
loggerProviderILoggerProviderThe sink's provider, which the log keeps for the process's life.
Exceptions
- ArgumentNullException
loggerProvideris null.
Format(IEnumerable<IPAddress>)
Wraps IP addresses for a log line, redacted by the current redactor when the line turns it into text.
public static Redactor.RedactedValue<IReadOnlyList<IPAddress>> Format(IEnumerable<IPAddress> ipAddresses)
Parameters
ipAddressesIEnumerable<IPAddress>The addresses.
Returns
- Redactor.RedactedValue<IReadOnlyList<IPAddress>>
A wrapper that formats on each
ToString, with the redactor captured by this call.
Remarks
In anonymous mode a globally routable address becomes a token, stable within the run; a private or local address, a port, a prefix length and an endpoint that is not an IP one stay as they are, and several values are joined by commas. A conversion or a copy of a sequence happens now; the redaction each time the text is made.
Format(IEnumerable<IpNetwork>)
Wraps networks for a log line, redacted by the current redactor when the line turns it into text.
public static Redactor.RedactedValue<IReadOnlyList<IpNetwork>> Format(IEnumerable<IpNetwork> ipNetworks)
Parameters
ipNetworksIEnumerable<IpNetwork>The networks.
Returns
- Redactor.RedactedValue<IReadOnlyList<IpNetwork>>
A wrapper that formats on each
ToString, with the redactor captured by this call.
Remarks
In anonymous mode a globally routable address becomes a token, stable within the run; a private or local address, a port, a prefix length and an endpoint that is not an IP one stay as they are, and several values are joined by commas. A conversion or a copy of a sequence happens now; the redaction each time the text is made.
Format(EndPoint?)
Wraps an endpoint for a log line, redacted by the current redactor when the line turns it into text.
public static Redactor.RedactedValue<EndPoint> Format(EndPoint? endPoint)
Parameters
Returns
- Redactor.RedactedValue<EndPoint>
A wrapper that formats on each
ToString, with the redactor captured by this call.
Remarks
In anonymous mode a globally routable address becomes a token, stable within the run; a private or local address, a port, a prefix length and an endpoint that is not an IP one stay as they are, and several values are joined by commas. A conversion or a copy of a sequence happens now; the redaction each time the text is made.
Format(IPAddress?)
Wraps an IP address for a log line, redacted by the current redactor when the line turns it into text.
public static Redactor.RedactedValue<IPAddress> Format(IPAddress? ipAddress)
Parameters
Returns
- Redactor.RedactedValue<IPAddress>
A wrapper that formats on each
ToString, with the redactor captured by this call.
Remarks
In anonymous mode a globally routable address becomes a token, stable within the run; a private or local address, a port, a prefix length and an endpoint that is not an IP one stay as they are, and several values are joined by commas. A conversion or a copy of a sequence happens now; the redaction each time the text is made.
Format(IPEndPoint?)
Wraps an endpoint for a log line, redacted by the current redactor when the line turns it into text.
public static Redactor.RedactedValue<EndPoint> Format(IPEndPoint? endPoint)
Parameters
endPointIPEndPointThe endpoint, or null.
Returns
- Redactor.RedactedValue<EndPoint>
A wrapper that formats on each
ToString, with the redactor captured by this call.
Remarks
In anonymous mode a globally routable address becomes a token, stable within the run; a private or local address, a port, a prefix length and an endpoint that is not an IP one stay as they are, and several values are joined by commas. A conversion or a copy of a sequence happens now; the redaction each time the text is made.
Format(IpEndPointValue?)
Wraps an endpoint for a log line, redacted by the current redactor when the line turns it into text.
public static Redactor.RedactedValue<EndPoint> Format(IpEndPointValue? endPoint)
Parameters
endPointIpEndPointValue?The endpoint, or null.
Returns
- Redactor.RedactedValue<EndPoint>
A wrapper that formats on each
ToString, with the redactor captured by this call.
Remarks
In anonymous mode a globally routable address becomes a token, stable within the run; a private or local address, a port, a prefix length and an endpoint that is not an IP one stay as they are, and several values are joined by commas. A conversion or a copy of a sequence happens now; the redaction each time the text is made.
Exceptions
- InvalidOperationException
The endpoint is the default value, which holds no address.
- ArgumentOutOfRangeException
The endpoint's port is out of range.
Format(IpNetwork?)
Wraps a network for a log line, redacted by the current redactor when the line turns it into text.
public static Redactor.RedactedValue<IpNetwork> Format(IpNetwork? ipNetwork)
Parameters
Returns
- Redactor.RedactedValue<IpNetwork>
A wrapper that formats on each
ToString, with the redactor captured by this call.
Remarks
In anonymous mode a globally routable address becomes a token, stable within the run; a private or local address, a port, a prefix length and an endpoint that is not an IP one stay as they are, and several values are joined by commas. A conversion or a copy of a sequence happens now; the redaction each time the text is made.
FormatHostName(string?)
Formats a host name for the log: a name that is an address or an endpoint is redacted as one; another, in anonymous mode, shows only its last four characters, and a name over eight characters its first two too.
public static string FormatHostName(string? dnsName)
Parameters
Returns
- string
The text.
FormatHostName(string?, int)
Formats a host name and a port for the log, as host:port; the host as FormatHostName(string?) does.
public static string FormatHostName(string? dnsName, int port)
Parameters
Returns
- string
The text.
FormatId(object?)
Formats an identifying ID for the log. In anonymous mode only its second half shows, after **.
public static string FormatId(object? id)
Parameters
Returns
- string
The text.
FormatIpPacket(string)
Formats a packet's text for the log. In anonymous mode the addresses after its source and destination labels are
redacted as Format redacts an address.
public static string FormatIpPacket(string ipPacketText)
Parameters
ipPacketTextstringThe packet's text.
Returns
- string
The text.
FormatSessionId(object?)
Formats a session ID for the log, as it is: it is not redacted.
public static string FormatSessionId(object? id)
Parameters
Returns
- string
The ID's text, or
<null>.
FormatType(object?)
Formats an object's type for the log: its name.
public static string FormatType(object? obj)
Parameters
Returns
- string
The type's name, or
<null>.
FormatType<T>()
Formats a type for the log: its name.
public static string FormatType<T>()
Returns
- string
The type's name.
Type Parameters
TThe type.
IsSocketCloseException(Exception)
Determines whether an exception, or one along its InnerException chain, is a disposal, a cancellation, or a socket error of an aborted, reset or refused connection, an aborted operation or a network reset, wherever it comes from.
public static bool IsSocketCloseException(Exception ex)
Parameters
exExceptionThe exception.
Returns
LogError(EventId, Exception, string, params object?[])
Logs an error, or, for what IsSocketCloseException(Exception) accepts, a Debug line with TcpCloseEventId and the outer exception's message, without the exception.
public static void LogError(EventId eventId, Exception ex, string message, params object?[] args)