LogMessage Class

Defines helper methods for generating log messages.

public static class LogMessage
Inheritance:
object object

Methods

AppendNamedValues(string?, params object?[])

Creates a message with a list of key/value pairs that are automatically formatted.

public static string? AppendNamedValues(string? message, params object?[] args)
Parameter Type Description
message string

A message to be displayed before the list of values.

args object[]

The array of objects defining the keys and values as alternating entries (e.g. key0, value0, key1, value1).

Returns

string:

The list of key/value pairs.

Exceptions

Type Condition
ArgumentException

Thrown if the arguments cannot be evenly divided into pairs.

AppendNamedValues<TKey, TValue>(string?, ValueListStyle, IEnumerable<KeyValuePair<TKey, TValue>>)

Creates a message with a list of key/value pairs.

public static string? AppendNamedValues<TKey, TValue>(string? message, ValueListStyle style, IEnumerable<KeyValuePair<TKey, TValue>> keyValuePairs)
Type Parameters:
TKey -
TValue -
Parameter Type Description
message string

A message to be displayed before the list of values.

style ValueListStyle

The style of list to be generated.

keyValuePairs IEnumerable<KeyValuePair<TKey, TValue>>

An IEnumerable<T> of KeyValuePair<TKey, TValue> to be listed.

Returns

string:

The list of key/value pairs.

AppendNamedValues<TKey, TValue>(string?, IEnumerable<KeyValuePair<TKey, TValue>>)

Creates a message with a list of key/value pairs using a style that is automatically determined.

public static string? AppendNamedValues<TKey, TValue>(string? message, IEnumerable<KeyValuePair<TKey, TValue>> keyValuePairs)
Type Parameters:
TKey -
TValue -
Parameter Type Description
message string

A message to be displayed before the list of values.

keyValuePairs IEnumerable<KeyValuePair<TKey, TValue>>

An IEnumerable<T> of KeyValuePair<TKey, TValue> to be listed.

Returns

string:

The list of key/value pairs.

CoerceAsKeyValuePairs(params object?[])

Coerces an array of objects into key-value pairs for every two objects in the array (e.g., first pair is index 0 and 1, second pair is index 2 and 3).

public static IEnumerable<KeyValuePair<object?, object?>> CoerceAsKeyValuePairs(params object?[] args)
Parameter Type Description
args object[]

The array of objects defining the keys and values as alternating entries (e.g. key0, value0, key1, value1).

Returns

IEnumerable<KeyValuePair<object, object>>:

An IEnumerable<T> of KeyValuePair<TKey, TValue>.

Exceptions

Type Condition
ArgumentException

Thrown if the array cannot be evenly divided into pairs.

CoerceAsString(object?)

Coerces the given value into a string for logging.

public static string CoerceAsString(object? value)
Parameter Type Description
value object

The value to coerce.

Returns

string:

The coerced string value.

FormatStringWithNullTextReplacement(string?, params object?[])

Formats a message using string.Format(string, object?[]) after replacing any null arguments with a placeholder string.

public static string FormatStringWithNullTextReplacement(string? message, params object?[] args)
Parameter Type Description
message string

The message to be formatted.

args object[]

The arguments.

Returns

string:

The formatted string.

MethodCall(object?, string, IEnumerable<KeyValuePair<string, object?>>)

Creates a message used to describe a method call.

public static string MethodCall(object? callerInstance, string callerMemberName, IEnumerable<KeyValuePair<string, object?>> argumentData)
Parameter Type Description
callerInstance object

The instance of the caller object or null if the caller object is static.

callerMemberName string

The name of the method that is called.

argumentData IEnumerable<KeyValuePair<string, object>>

An IEnumerable<T> of KeyValuePair<TKey, TValue> of relevant argument names and their values.

Returns

string:

A string describing the method call.

MethodCall(object?, string, params object?[])

Creates a message used to describe a method call.

public static string MethodCall(object? callerInstance, string callerMemberName, params object?[] argumentData)
Parameter Type Description
callerInstance object

The instance of the caller object or null if the caller object is static.

callerMemberName string

The name of the method that is called.

argumentData object[]

The array of objects defining relevant argument names and their values as alternating entries (e.g. arg0, value0, arg1, value1).

Returns

string:

A string describing the method call.

Exceptions

Type Condition
ArgumentException

Thrown if the argument data cannot be evenly divided into pairs.

NamedValues(params object?[])

Creates a message that is a list of key/value pairs using a style that is automatically determined.

public static string? NamedValues(params object?[] args)
Parameter Type Description
args object[]

The array of objects defining the keys and values as alternating entries (e.g. key0, value0, key1, value1).

Returns

string:

The list of key/value pairs.

Exceptions

Type Condition
ArgumentException

Thrown if the arguments cannot be evenly divided into pairs.

NamedValues<TKey, TValue>(ValueListStyle, IEnumerable<KeyValuePair<TKey, TValue>>)

Creates a message that is a list of key/value pairs.

public static string? NamedValues<TKey, TValue>(ValueListStyle style, IEnumerable<KeyValuePair<TKey, TValue>> keyValuePairs)
Type Parameters:
TKey -
TValue -
Parameter Type Description
style ValueListStyle

The style of list to be generated.

keyValuePairs IEnumerable<KeyValuePair<TKey, TValue>>

An IEnumerable<T> of KeyValuePair<TKey, TValue> to be listed.

Returns

string:

The list of key/value pairs.

NamedValues<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>>)

Creates a message that is a list of key/value pairs using a style that is automatically determined.

public static string? NamedValues<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>> keyValuePairs)
Type Parameters:
TKey -
TValue -
Parameter Type Description
keyValuePairs IEnumerable<KeyValuePair<TKey, TValue>>

An IEnumerable<T> of KeyValuePair<TKey, TValue> to be listed.

Returns

string:

The list of key/value pairs.

Inherited Members