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
tokens
IEnumerable<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
text
stringThe full text of the template; used by Serilog internally to avoid unneeded string concatenation.
tokens
IEnumerable<MessageTemplateToken>The text and property tokens defining the template.
Exceptions
- ArgumentNullException
When
text
isnull
- ArgumentNullException
When
tokens
isnull
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
properties
IReadOnlyDictionary<string, LogEventPropertyValue>Properties matching template tokens.
formatProvider
IFormatProviderSupplies 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
properties
isnull
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
properties
IReadOnlyDictionary<string, LogEventPropertyValue>Properties matching template tokens.
output
TextWriterThe message created from the template and properties. If the properties are mismatched with the template, the template will be returned with incomplete substitution.
formatProvider
IFormatProviderSupplies culture-specific formatting information, or null.
Exceptions
- ArgumentNullException
When
properties
isnull
- ArgumentNullException
When
output
isnull
ToString()
Render the template as a string.
public override string ToString()
Returns
- string
The string representation of the template.