Table of Contents

Class LoggerWrapperExtensions

Namespace
Arc4u.Diagnostics
Assembly
Arc4u.Diagnostics.dll

Fluent extension methods that add properties to the additional fields of an ILoggerWrapper<T>; they are written with the next log entry of that logger.

public static class LoggerWrapperExtensions
Inheritance
LoggerWrapperExtensions
Inherited Members

Remarks

The keys defined in LoggingConstants are reserved: using one of them throws a ReservedLoggingKeyException. The properties are cleared once the entry is written: they never appear on later entries.

Methods

AddIfNotExist<T>(ILoggerWrapper<T>, string, object?)

Adds a property to the additional fields of the logger only when the key is not already present and the value is not null; otherwise nothing changes.

public static ILoggerWrapper<T> AddIfNotExist<T>(this ILoggerWrapper<T> logger, string key, object? value)

Parameters

logger ILoggerWrapper<T>

The logger wrapper.

key string

The property name.

value object

The property value; a null value is ignored.

Returns

ILoggerWrapper<T>

The same logger wrapper, for chaining.

Type Parameters

T

The category type of the logger.

Exceptions

ArgumentNullException

key is null, empty or white space.

ReservedLoggingKeyException

key is one of the names reserved in LoggingConstants.

AddIf<T>(ILoggerWrapper<T>, bool, string, Func<object>)

Adds a property to the additional fields of the logger, replacing the value if the key is already present, only when the condition is true.

public static ILoggerWrapper<T> AddIf<T>(this ILoggerWrapper<T> logger, bool condition, string key, Func<object> value)

Parameters

logger ILoggerWrapper<T>

The logger wrapper.

condition bool

When false, nothing is added and value is not evaluated.

key string

The property name.

value Func<object>

A function that provides the property value; it is called only when the condition is true.

Returns

ILoggerWrapper<T>

The same logger wrapper, for chaining.

Type Parameters

T

The category type of the logger.

Exceptions

ArgumentNullException

key is null, empty or white space and the condition is true.

ReservedLoggingKeyException

key is reserved in LoggingConstants and the condition is true.

AddMemoryUsage<T>(ILoggerWrapper<T>)

Adds a Memory property holding the number of bytes currently thought to be allocated (GetTotalMemory(bool) without forcing a collection).

public static ILoggerWrapper<T> AddMemoryUsage<T>(this ILoggerWrapper<T> logger)

Parameters

logger ILoggerWrapper<T>

The logger wrapper.

Returns

ILoggerWrapper<T>

The same logger wrapper, for chaining.

Type Parameters

T

The category type of the logger.

AddOrReplaceIf<T>(ILoggerWrapper<T>, bool, string, Func<double>)

Adds a numeric property to the additional fields of the logger, or replaces its value if the key is already present, only when the condition is true.

public static ILoggerWrapper<T> AddOrReplaceIf<T>(this ILoggerWrapper<T> logger, bool condition, string key, Func<double> value)

Parameters

logger ILoggerWrapper<T>

The logger wrapper.

condition bool

When false, nothing is added and value is not evaluated.

key string

The property name.

value Func<double>

A function that provides the numeric property value; it is called only when the condition is true.

Returns

ILoggerWrapper<T>

The same logger wrapper, for chaining.

Type Parameters

T

The category type of the logger.

Exceptions

ArgumentNullException

key is null, empty or white space and the condition is true.

ReservedLoggingKeyException

key is reserved in LoggingConstants and the condition is true.

AddOrReplace<T>(ILoggerWrapper<T>, string, object)

Adds a property to the additional fields of the logger, or replaces its value if the key is already present.

public static ILoggerWrapper<T> AddOrReplace<T>(this ILoggerWrapper<T> logger, string key, object value)

Parameters

logger ILoggerWrapper<T>

The logger wrapper.

key string

The property name.

value object

The property value.

Returns

ILoggerWrapper<T>

The same logger wrapper, for chaining.

Type Parameters

T

The category type of the logger.

Exceptions

ArgumentNullException

key is null, empty or white space.

ReservedLoggingKeyException

key is one of the names reserved in LoggingConstants.

AddStackTrace<T>(ILoggerWrapper<T>)

Requests that the stack trace is added, in the Stacktrace property, to the log entries: the stack trace of the exception when one is logged, otherwise the current stack trace.

public static ILoggerWrapper<T> AddStackTrace<T>(this ILoggerWrapper<T> logger)

Parameters

logger ILoggerWrapper<T>

The logger wrapper.

Returns

ILoggerWrapper<T>

The same logger wrapper, for chaining.

Type Parameters

T

The category type of the logger.

Remarks

The request applies to the next entry only.

Add<T>(ILoggerWrapper<T>, string, object)

Adds a property to the additional fields of the logger, replacing the value if the key is already present.

public static ILoggerWrapper<T> Add<T>(this ILoggerWrapper<T> logger, string key, object value)

Parameters

logger ILoggerWrapper<T>

The logger wrapper.

key string

The property name.

value object

The property value.

Returns

ILoggerWrapper<T>

The same logger wrapper, for chaining.

Type Parameters

T

The category type of the logger.

Exceptions

ArgumentNullException

key is null, empty or white space.

ReservedLoggingKeyException

key is one of the names reserved in LoggingConstants.