Open sandboxFocus

Class LogLevelSource

A facade for a LogSource constrained to a specific LogLevel. Instances of the LogLevelSource class are exposed as properties of the LogSource class, for example Debug or Error.

Inheritance
LogLevelSource
Namespace: PostSharp.Patterns.Diagnostics.Custom
Assembly: PostSharp.Patterns.Common.dll
Syntax
[RequirePostSharp("PostSharp.Patterns.Common.Weaver", "AddCallerInfoTask", AnyTypeReference = true)]
[RequirePostSharp(typeof(AwaitInstrumentationAspectProvider), AnyTypeReference = true)]
public sealed class LogLevelSource
Remarks

Use Write<T>(in T, in WriteMessageOptions) to write a message, and OpenActivity<T>(in T, in OpenActivityOptions) to open an activity that you close explicitly. The LogActivity<TDescription>(in TDescription, Action, in OpenActivityOptions) and LogActivityAsync<TDescription>(in TDescription, Func<Task>, in OpenActivityOptions) methods and their overloads execute a delegate within an activity and close it for you, but the delegate is typically a closure that is allocated even when logging is disabled.

When evaluating the arguments of a message is expensive, use the EnabledOrNull property with the ?. operator, so that the arguments are evaluated only when the Level is enabled.

When PostSharp processes a project that uses this class, it adds caller information to the calls and instruments await expressions.

Properties

Name Description
EnabledOrNull

Gets the current LogLevelSource, or null if logging is not enabled for the current instance. This property allows writing conditional logging using the ?. operator.

IsEnabled

Gets a value indicating whether logging is enabled for the current Level.

Level

Gets the LogLevel to which the current LogLevelSource is constrained.

Methods

Name Description
LogActivityAsync<TDescription>(in TDescription, Func<Task>, in OpenActivityOptions)

Executes an asynchronous void delegate and logs its execution.

LogActivityAsync<TDescription, TResult>(in TDescription, Func<Task<TResult>>, in OpenActivityOptions)

Executes an asynchronous non-void delegate and logs its execution.

LogActivity<TDescription>(in TDescription, Action, in OpenActivityOptions)

Executes an Action and logs its execution.

LogActivity<TDescription, TResult>(in TDescription, Func<TResult>, in OpenActivityOptions)

Executes a Func<TResult> and logs its execution.

OpenActivity<T>(in T, in OpenActivityOptions)

Opens an activity.

Write<T>(in T, in WriteMessageOptions)

Writes a message.

Write<T>(in T, Exception, in WriteMessageOptions)

Writes a message and specifies an Exception.

See Also