Class PatternString
This class implements a patterned string.
public class PatternString : IOptionHandler
- Inheritance
-
PatternString
- Implements
- Inherited Members
Remarks
This string has embedded patterns that are resolved and expanded when the string is formatted.
This class functions similarly to the PatternLayout
in that it accepts a pattern and renders it to a string. Unlike the
PatternLayout however the PatternString
does not render the properties of a specific LoggingEvent but
of the process in general.
The recognized conversion pattern names are:
| Conversion Pattern Name | Effect |
|---|---|
| appdomain |
Used to output the friendly name of the current AppDomain. |
| appsetting |
Used to output the value of a specific appSetting key in the application configuration file. |
| date |
Used to output the current date and time in the local time zone.
To output the date in universal time use the The date format specifier admits the same syntax as the time pattern string of the DateTime.ToString(string). For better results it is recommended to use the log4net date formatters. These can be specified using one of the strings "ABSOLUTE", "DATE" and "ISO8601" for specifying AbsoluteTimeDateFormatter, DateTimeDateFormatter and respectively Iso8601DateFormatter. For example, %date{ISO8601} or %date{ABSOLUTE}. These dedicated date formatters perform significantly better than DateTime.ToString(string). |
| env |
Used to output the a specific environment variable. The key to
lookup must be specified within braces and directly following the
pattern specifier, e.g. %env{COMPUTERNAME} would include the value
of the
The |
| identity |
Used to output the user name for the currently active user (Principal.Identity.Name). |
| newline |
Outputs the platform dependent line separator character or characters. This conversion pattern name offers the same performance as using non-portable line separator strings such as "\n", or "\r\n". Thus, it is the preferred way of specifying a line separator. |
| processid |
Used to output the system process ID for the current process. |
| property |
Used to output a specific context property. The key to
lookup must be specified within braces and directly following the
pattern specifier, e.g. %property{user} would include the value
from the property that is keyed by the string 'user'. Each property value
that is to be included in the log must be specified separately.
Properties are stored in logging contexts. By default
the If no key is specified, e.g. %property then all the keys and their values are printed in a comma separated list. The properties of an event are combined from a number of different contexts. These are listed below in the order in which they are searched.
Additional pattern converters may be registered with a specific PatternString
instance using AddConverter(ConverterInfo) or
See the PatternLayout for details on the format modifiers supported by the patterns. |
Constructors
PatternString()
Default constructor
public PatternString()
Remarks
Initialize a new instance of PatternString
PatternString(string)
Constructs a PatternString
public PatternString(string pattern)
Parameters
patternstringThe pattern to use with this PatternString
Remarks
Initialize a new instance of PatternString with the pattern specified.
Properties
ConversionPattern
Gets or sets the pattern formatting string
public string ConversionPattern { get; set; }
Property Value
- string
The pattern formatting string
Remarks
The ConversionPattern option. This is the string which controls formatting and consists of a mix of literal content and conversion specifiers.
Methods
ActivateOptions()
Initialize object options
public virtual void ActivateOptions()
Remarks
This is part of the IOptionHandler delayed object activation scheme. The ActivateOptions() method must be called on this object after the configuration properties have been set. Until ActivateOptions() is called this object is in an undefined state and must not be used.
If any of the configuration properties are modified then ActivateOptions() must be called again.
AddConverter(string, Type)
Add a converter to this PatternString
public void AddConverter(string name, Type type)
Parameters
namestringthe name of the conversion pattern for this converter
typeTypethe type of the converter
Remarks
Add a converter to this PatternString
AddConverter(ConverterInfo)
Add a converter to this PatternString
public void AddConverter(ConverterInfo converterInfo)
Parameters
converterInfoConverterInfothe converter info
Remarks
This version of the method is used by the configurator. Programmatic users should use the alternative AddConverter(string,Type) method.
Format()
Format the pattern as a string
public string Format()
Returns
- string
the pattern formatted as a string
Remarks
Format the pattern to a string.
Format(TextWriter)
Produces a formatted string as specified by the conversion pattern.
public void Format(TextWriter writer)
Parameters
writerTextWriterThe TextWriter to write the formatted event to
Remarks
Format the pattern to the writer.