Allows writing log messages and tracing 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.
Namespace: PostSharp.Patterns.Diagnostics
Assembly: PostSharp.Patterns.Common.dll
Syntax
[RequirePostSharp("PostSharp.Patterns.Common.Weaver", "AddCallerInfoTask", AnyTypeReference = true)]
public sealed class LogSourceRemarks
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.
The Default and Failure properties resolve to Debug and Error. To change these levels for several types from a central place, configure a prototype instance with WithLevels(LogLevel, LogLevel), then derive the instance of each type from it with ForCurrentType() or ForType(Type). The failure level is also the level of the closing message of an activity that fails.
Projects that use this class should be processed by PostSharp. Otherwise, the caller information is determined at run time by walking the call stack, which is slower.
Properties
| Name | Description |
|---|---|
| Critical | Gets a LogLevelSource that exposes methods to write messages and open activities with the Critical severity. |
| CurrentContext | |
| Debug | Gets a LogLevelSource that exposes methods to write messages and open activities with the Debug severity. |
| Default | Gets a LogLevelSource that exposes methods to write messages and open activities with the default severity of the current LogSource. The default severity is Debug, unless it has been overridden by the WithLevels(LogLevel, LogLevel) method. |
| Error | Gets a LogLevelSource that exposes methods to write messages and open activities with the Error severity. |
| Failure | Gets a LogLevelSource that exposes methods to write messages and open activities with the default failure severity of the current LogSource. The default severity is Error, unless it has been overridden by the WithLevels(LogLevel, LogLevel) method. |
| Info | Gets a LogLevelSource that exposes methods to write messages and open activities with the Info severity. |
| None | Gets a LogLevelSource that exposes methods to open activities with the None severity. Such activities are never displayed, but they can define properties that child activities and messages can inherit. |
| Trace | Gets a LogLevelSource that exposes methods to write messages and open activities with the Trace severity. |
| Warning | Gets a LogLevelSource that exposes methods to write messages and open activities with the Warning severity. |
Methods
| Name | Description |
|---|---|
| ApplyTransactionRequirements(ref OpenActivityOptions) | Evaluates whether a transaction needs to be opened 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 called automatically. |
| ForCurrentType() | Gets a new LogSource that keeps all the configuration of the current instance but is for the calling type. |
| ForSource(string) | Gets a new LogSource that keeps all the configuration of the current instance but is for a source name. |
| ForType(Type) | Gets a new LogSource that keeps all the configuration of the current instance but is 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) | Gets a LogLevelSource that exposes methods to write messages and open activities with a specified LogLevel. |
| WithLevels(LogLevel, LogLevel) | Returns a new LogSource that is 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. |