Table of Contents

Class LogContractRenderer

Namespace
LogAssertions.Render
Assembly
LogAssertions.dll

Pure renderer that writes a service's log contract (the event IDs, names, levels, message templates, and placeholder names of its log definitions) as deterministic text, one line per definition:

1201 OrderProcessed Information "Order {OrderId} processed in {DurationMs} ms" OrderId,DurationMs

Dashboards, log parsers, and analysis scripts read exactly these parts; composed with MatchesSnapshot(), the contract becomes a reviewed baseline, and a renamed placeholder or a reworded template shows as a diff.

public static class LogContractRenderer
Inheritance
LogContractRenderer
Inherited Members

Examples

var contract = LogContractRenderer.Render([OrderProcessed, OrderShipped, PaymentFailed]);
await Assert.That(contract).MatchesSnapshot();

Remarks

Format. Each line is the numeric event ID, the event name (? when the definition has none), the level, the message template in double quotes (<no template> when the call carried none), and the placeholder names in template order, separated by commas, with {OriginalFormat} left out. A definition without placeholders ends after the template. In the template, the event name, and the placeholder names, \, ", carriage return, line feed, and tab are written as \\, \", \r, \n, and \t, so every definition stays on one line.

Deterministic. Lines are ordered by event ID, then event name, then template (both ordinal), then level, then the line itself (ordinal), whatever the input order. Every line ends with the literal LF byte ('\n'), never NewLine, so a baseline committed on one operating system stays valid on every other. There is no header line, as with LogSnapshotRenderer; a change to the format is a listed breaking change.

Sources. The renderer reads only Id, Level, Template, and Properties, with no reflection. Capture each definition with Capture(Action<ILogger>); the argument values of the capture are not rendered.

Methods

Render(IEnumerable<LogDefinition>)

Renders one line per definition, ordered by event ID, name, template, level, and the line itself.

public static string Render(IEnumerable<LogDefinition> definitions)

Parameters

definitions IEnumerable<LogDefinition>

The definitions of the contract. Must not contain null.

Returns

string

The contract: one LF-terminated line per definition, or Empty when there are none.

Exceptions

ArgumentNullException

definitions is null.

ArgumentException

definitions contains a null definition.