Open sandboxFocus

Class FormattedMessageBuilder

Creates messages based on a human-readable formatted string. These messages are suitable for structured logging but are not optimal for machine analysis. For more succinct code, consider including the using static PostSharp.Patterns.Diagnostics.FormattedMessageBuilder statement.

Inheritance
FormattedMessageBuilder
Namespace: PostSharp.Patterns.Diagnostics
Assembly: PostSharp.Patterns.Common.dll
Syntax
public static class FormattedMessageBuilder
Remarks

The formatting string is not the one of Format(string, params object[]). Parameters are named and surrounded by curly brackets, for example {BufferSize}, and are matched to the values by position, not by name. The formatting string must contain exactly one parameter per value. The text between the brackets is passed to the logging backend as the parameter name, without further parsing, so format specifiers are not supported. To write a literal curly bracket, double it ({{ or }}).

The values keep their own types and are rendered only when the message is written. Prefer this class over Format(string, params object[]) or interpolated strings, which build a string even when the logging level is disabled. When messages need to be counted or aggregated, use SemanticMessageBuilder instead.

Methods

Name Description
Formatted(string)

Creates a text message with no formatting string parameter.

Formatted(string, object[])

Creates a formatted string with an arbitrary number of parameters.

Formatted<T1>(string, T1)

Creates a formatted string with 1 parameter.

Formatted<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(string, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)

Creates a formatted string with 10 parameters.

Formatted<T1, T2>(string, T1, T2)

Creates a formatted string with 2 parameters.

Formatted<T1, T2, T3>(string, T1, T2, T3)

Creates a formatted string with 3 parameters.

Formatted<T1, T2, T3, T4>(string, T1, T2, T3, T4)

Creates a formatted string with 4 parameters.

Formatted<T1, T2, T3, T4, T5>(string, T1, T2, T3, T4, T5)

Creates a formatted string with 5 parameters.

Formatted<T1, T2, T3, T4, T5, T6>(string, T1, T2, T3, T4, T5, T6)

Creates a formatted string with 6 parameters.

Formatted<T1, T2, T3, T4, T5, T6, T7>(string, T1, T2, T3, T4, T5, T6, T7)

Creates a formatted string with 7 parameters.

Formatted<T1, T2, T3, T4, T5, T6, T7, T8>(string, T1, T2, T3, T4, T5, T6, T7, T8)

Creates a formatted string with 8 parameters.

Formatted<T1, T2, T3, T4, T5, T6, T7, T8, T9>(string, T1, T2, T3, T4, T5, T6, T7, T8, T9)

Creates a formatted string with 9 parameters.

See Also