Class MessageTemplate
Represents a message template passed to a log method. The template can subsequently render the template in textual form given the list of properties.
public class MessageTemplate
- Inheritance
-
MessageTemplate
- Inherited Members
Constructors
MessageTemplate(IEnumerable<MessageTemplateToken>)
Construct a message template using manually-defined text and property tokens.
public MessageTemplate(IEnumerable<MessageTemplateToken> tokens)
Parameters
tokensIEnumerable<MessageTemplateToken>The text and property tokens defining the template.
MessageTemplate(string, IEnumerable<MessageTemplateToken>)
Construct a message template using manually-defined text and property tokens.
public MessageTemplate(string text, IEnumerable<MessageTemplateToken> tokens)
Parameters
textstringThe full text of the template; used by Serilog internally to avoid unneeded string concatenation.
tokensIEnumerable<MessageTemplateToken>The text and property tokens defining the template.
Exceptions
- ArgumentNullException
When
textisnull- ArgumentNullException
When
tokensisnull
Properties
Empty
Represents the empty message template.
public static MessageTemplate Empty { get; }
Property Value
Text
The raw text describing the template.
public string Text { get; }
Property Value
Tokens
The tokens parsed from the template.
public IEnumerable<MessageTemplateToken> Tokens { get; }
Property Value
Methods
Render(IReadOnlyDictionary<string, LogEventPropertyValue>, IFormatProvider?)
Convert the message template into a textual message, given the properties matching the tokens in the message template.
public string Render(IReadOnlyDictionary<string, LogEventPropertyValue> properties, IFormatProvider? formatProvider = null)
Parameters
propertiesIReadOnlyDictionary<string, LogEventPropertyValue>Properties matching template tokens.
formatProviderIFormatProviderSupplies culture-specific formatting information, or null.
Returns
- string
The message created from the template and properties. If the properties are mismatched with the template, the template will be returned with incomplete substitution.
Exceptions
- ArgumentNullException
When
propertiesisnull
Render(IReadOnlyDictionary<string, LogEventPropertyValue>, TextWriter, IFormatProvider?)
Convert the message template into a textual message, given the properties matching the tokens in the message template.
public void Render(IReadOnlyDictionary<string, LogEventPropertyValue> properties, TextWriter output, IFormatProvider? formatProvider = null)
Parameters
propertiesIReadOnlyDictionary<string, LogEventPropertyValue>Properties matching template tokens.
outputTextWriterThe message created from the template and properties. If the properties are mismatched with the template, the template will be returned with incomplete substitution.
formatProviderIFormatProviderSupplies culture-specific formatting information, or null.
Exceptions
- ArgumentNullException
When
propertiesisnull- ArgumentNullException
When
outputisnull
ToString()
Render the template as a string.
public override string ToString()
Returns
- string
The string representation of the template.