Open sandboxFocus

Class LogSource

Allow to write log messages and trace the execution of activities. This class is optimized for use with C# 7.2 or later. For previous compiler versions, consider using the legacy PostSharp.Patterns.Diagnostics.LogSource.Logger class.

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

Instances of this class are immutable.

You should typically have one instance of this class per type. Use Get() or GetLogSource(ILoggerFactory2, Type) to get an instance of this class for the current type.

Properties

Name Description
Critical

Exposes methods that allow to write messages and open activities with the Critical severity.

CurrentContext
Debug

Exposes methods that allow to write messages and open activities with the Debug severity.

Default

Exposes methods that allow to write messages and open activities with the default severity of the current LogSource. The default severity is Debug, unless it has been overwritten by the WithLevels(LogLevel, LogLevel) method.

Error

Exposes methods that allow to write messages and open activities with the Error severity.

Failure

Exposes methods that allow to write messages and open activities with the default failure severity of the current LogSource. The default severity is Error, unless it has been overwritten by the WithLevels(LogLevel, LogLevel) method.

Info

Exposes methods that allow to write messages and open activities with the Info severity.

None

Exposes methods that allow to open activities with the None severity. Such activities are never displayed, but they can define properties that can be inherited to children activities and messages.

Trace

Exposes methods that allow to write messages and open activities with the Trace severity.

Warning

Exposes methods that allow to write messages and open activities with the Warning severity.

Methods

Name Description
ApplyTransactionRequirements(ref OpenActivityOptions)

Evaluates whether a transaction needs to be open for a specified OpenActivityOptions and updates its TransactionRequirement property. This method must be invoked before calling OpenActivity<T>(in T, in OpenActivityOptions). It is not automatically called.

ForCurrentType()

Gets a new LogSource keeping all the configuration of the current instance, but for the calling type.

ForSource(string)

Gets a new LogSource keeping all the configuration of the current instance, but for a source name.

ForType(Type)

Gets a new LogSource keeping all the configuration of the current instance, but for a different type.

Get()

Gets a LogSource for the calling type.

Get(string)

Gets a log source associated with a specific source name.

Get(string, string)

Gets a log source for a specified role and source name.

Get(Type, string)

Gets a log source for a specified role and Type.

IsEnabled(LogLevel)

Determines whether logging is enabled in the current LogSource for a given LogLevel.

WithLevel(LogLevel)

Exposes methods that allow to write messages and open activities with a specified LogLevel.

WithLevels(LogLevel, LogLevel)

Returns a new LogSource based on the current instance, but overrides the default logging levels.

WriteExecutionPoint()

Emits a log record with the source file and line of the caller.