Class TextFormatter
- Namespace
- Microsoft.Practices.EnterpriseLibrary.Logging.Formatters
- Assembly
- Microsoft.Practices.EnterpriseLibrary.Logging.dll
Represents a template based formatter for LogEntry messages.
public class TextFormatter : LogFormatter, ILogFormatter
- Inheritance
-
TextFormatter
- Implements
- Inherited Members
Remarks
The TextFormatter uses a GenericTextFormatter<T> initialized with a set of TokenHandler<T> that can manage the default template tokens. Subclasses can supply extra token handlers that will be added to the default set for additional template processing.
Constructors
TextFormatter()
Initializes a new instance of a TextFormatter with a default template.
public TextFormatter()
- See Also
-
TokenHandler<T>Formatter<T>
TextFormatter(string)
Initializes a new instance of a with a template and no extra token handlers.
public TextFormatter(string template)
Parameters
template
stringTemplate to be used when formatting.
- See Also
-
TokenHandler<T>Formatter<T>
TextFormatter(string, IDictionary<string, TokenHandler<LogEntry>>)
Initializes a new instance of a with a template and additional token handlers.
protected TextFormatter(string template, IDictionary<string, TokenHandler<LogEntry>> extraTokenHandlers)
Parameters
template
stringTemplate to be used when formatting.
extraTokenHandlers
IDictionary<string, TokenHandler<LogEntry>>The additional token handlers to use when processing the template.
- See Also
-
TokenHandler<T>Formatter<T>
Properties
DefaultTextFormat
Gets the default format to use when formatting.
public static string DefaultTextFormat { get; }
Property Value
- See Also
-
TokenHandler<T>Formatter<T>
Template
Gets or sets the formatting template.
public string Template { get; set; }
Property Value
- See Also
-
TokenHandler<T>Formatter<T>
Methods
Format(LogEntry)
Formats the LogEntry object by replacing tokens with values.
public override string Format(LogEntry log)
Parameters
log
LogEntryLog entry to format.
Returns
- string
Formatted string with tokens replaced with property values.
- See Also
-
TokenHandler<T>Formatter<T>
FormatCategoriesCollection(ICollection<string>)
Provides a textual representation of a categories list.
public static string FormatCategoriesCollection(ICollection<string> categories)
Parameters
categories
ICollection<string>The collection of categories.
Returns
- string
A comma delimited textural representation of the categories.
- See Also
-
TokenHandler<T>Formatter<T>
FormatFixedIsoDate(DateTime)
Generates ISO format yyyy-MM-dd
public static string FormatFixedIsoDate(DateTime date)
Parameters
date
DateTimeThe date time to format.
Returns
- string
A formatted date in the format yyyy-MM-dd
- See Also
-
TokenHandler<T>Formatter<T>
FormatFixedTime(DateTime)
Formats a date time with a fixed time format in a performant way.
public static string FormatFixedTime(DateTime date)
Parameters
date
DateTimeThe date time to format.
Returns
- string
A formatted time in the format HH:mm:ss.fff
- See Also
-
TokenHandler<T>Formatter<T>
FormatFixedUSDate(DateTime)
Formats a date time with a fixed US date format in a performant way.
public static string FormatFixedUSDate(DateTime date)
Parameters
date
DateTimeThe date time to format.
Returns
- string
A formatted date in the format MM/dd/yyyy
- See Also
-
TokenHandler<T>Formatter<T>