log4net SDK Reference |

# PatternString Class

This class implements a patterned string.

For a list of all members of this type, see PatternString Members.

System.Object
log4net.Util.PatternString

[Visual Basic]
Public Class PatternString
Implements IOptionHandler
[C#]
public class PatternString : IOptionHandler

#### Thread Safety

This type is not safe for multithreaded operations.

#### 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.
date | Used to output the date of the logging event in the local time zone. To output the date in universal time use the `%utcdate` pattern. The date conversion specifier may be followed by a date format specifier enclosed between braces. For example, %date{HH:mm:ss,fff} or %date{dd MMM yyyy HH:mm:ss,fff}. If no date format specifier is given then ISO8601 format is assumed (Iso8601DateFormatter). The date format specifier admits the same syntax as the time pattern string of the ToString. 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 ToString.
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 `COMPUTERNAME` environment variable. The `env` pattern is not supported on the .NET Compact Framework.
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 `log4net:HostName` property is set to the name of machine on which the event was originally logged. 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. the thread properties The Properties that are set on the current thread. These properties are shared by all events logged on this thread. the global properties The Properties that are set globally. These properties are shared by all the threads in the AppDomain.
random | Used to output a random string of characters. The string is made up of uppercase letters and numbers. By default the string is 4 characters long. The length of the string can be specified within braces directly following the pattern specifier, e.g. %random{8} would output an 8 character string.
username | Used to output the WindowsIdentity for the currently active user.
utcdate | Used to output the date of the logging event in universal time. The date conversion specifier may be followed by a date format specifier enclosed between braces. For example, %utcdate{HH:mm:ss,fff} or %utcdate{dd MMM yyyy HH:mm:ss,fff}. If no date format specifier is given then ISO8601 format is assumed (Iso8601DateFormatter). The date format specifier admits the same syntax as the time pattern string of the ToString. 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, %utcdate{ISO8601} or %utcdate{ABSOLUTE}. These dedicated date formatters perform significantly better than ToString.
% | The sequence %% outputs a single percent sign.

Additional pattern converters may be registered with a specific PatternString instance using AddConverter or AddConverter.

See the PatternLayout for details on the format modifiers supported by the patterns.

#### Requirements

Namespace: log4net.Util

Assembly: log4net (in log4net.dll)

#### See Also

PatternString Members | log4net.Util Namespace