Struct DebugLogHandler

Interpolated-string handler for Debug(string, ref DebugLogHandler).

Namespace: MOSAIC.Diagnostics
Assembly: MOSAIC.dll
Syntax
public ref struct DebugLogHandler
Remarks

This is the mechanism that makes a switched-off level genuinely free, and it is the only reason per-packet call sites on the Delsys, Muovi and BLE data threads are allowed to log at all.

Because the constructor has an out bool shouldAppend parameter, Roslyn rewrites Log.Debug("Delsys", $"frame {n} of {total}") into a handler construction followed by if (shouldAppend) { ...AppendLiteral/AppendFormatted... }. The interpolation holes themselves live inside that if, so when the level is off nothing is boxed, nothing is formatted, no string.Format runs and no array is allocated - the call costs one volatile read of MinimumLevel and a branch.

The inner DefaultInterpolatedStringHandler is constructed only when enabled, which is why every member checks _enabled before forwarding: an unconstructed inner handler must never be touched, and a logger that throws while logging is worse than no logger.

Constructors

DebugLogHandler(int, int, out bool)

Called by the compiler. Sets shouldAppend from the level gate.

Declaration
public DebugLogHandler(int literalLength, int formattedCount, out bool shouldAppend)
Parameters
Type Name Description
int literalLength

Total length of the literal parts, supplied by the compiler.

int formattedCount

Number of interpolation holes, supplied by the compiler.

bool shouldAppend

False when Debug is switched off.

Fields

_enabled

Declaration
private readonly bool _enabled
Field Value
Type Description
bool

_inner

Declaration
private DefaultInterpolatedStringHandler _inner
Field Value
Type Description
DefaultInterpolatedStringHandler

Properties

Enabled

Declaration
internal bool Enabled { get; }
Property Value
Type Description
bool

Methods

AppendFormatted(ReadOnlySpan<char>)

Appends a span hole without an intermediate string.

Declaration
public void AppendFormatted(ReadOnlySpan<char> value)
Parameters
Type Name Description
ReadOnlySpan<char> value

AppendFormatted(string?)

Appends a string hole without boxing it through the generic overload.

Declaration
public void AppendFormatted(string? value)
Parameters
Type Name Description
string value

AppendFormatted<T>(T)

Appends an interpolation hole.

Declaration
public void AppendFormatted<T>(T value)
Parameters
Type Name Description
T value
Type Parameters
Name Description
T

AppendFormatted<T>(T, int)

Appends an interpolation hole with an alignment.

Declaration
public void AppendFormatted<T>(T value, int alignment)
Parameters
Type Name Description
T value
int alignment
Type Parameters
Name Description
T

AppendFormatted<T>(T, int, string?)

Appends an interpolation hole with an alignment and a format string.

Declaration
public void AppendFormatted<T>(T value, int alignment, string? format)
Parameters
Type Name Description
T value
int alignment
string format
Type Parameters
Name Description
T

AppendFormatted<T>(T, string?)

Appends an interpolation hole with a format string.

Declaration
public void AppendFormatted<T>(T value, string? format)
Parameters
Type Name Description
T value
string format
Type Parameters
Name Description
T

AppendLiteral(string)

Appends a literal fragment of the interpolated string.

Declaration
public void AppendLiteral(string value)
Parameters
Type Name Description
string value

ToStringAndClear()

Declaration
internal string ToStringAndClear()
Returns
Type Description
string

Search documentation

Start typing to search the documentation.