Open sandboxFocus
  • TOC

Post­Sharp Documentation

Introduction

Deployment and Configuration

Adding Aspects to Code

Logging

Contracts

INotify­Property­Changed

Weak Event

XAML

Parent/Child, Visitor and Disposable

Undo/Redo

Caching

Multithreading

Developing Custom Aspects

Validating Architecture

Testing and Debugging

Miscellaneous

API Reference

Post­Sharp

Post­Sharp.​Aspects

Post­Sharp.​Aspects.​Advices

Post­Sharp.​Aspects.​Configuration

Post­Sharp.​Aspects.​Dependencies

Post­Sharp.​Aspects.​Internals

Post­Sharp.​Aspects.​Serialization

Post­Sharp.​Collections

Post­Sharp.​Constraints

Post­Sharp.​Extensibility

Post­Sharp.​Extensibility.​Build­Time­Logging

Post­Sharp.​Patterns

Post­Sharp.​Patterns.​Caching

Post­Sharp.​Patterns.​Caching.​Backends

Post­Sharp.​Patterns.​Caching.​Backends.​Azure

Post­Sharp.​Patterns.​Caching.​Backends.​Redis

Post­Sharp.​Patterns.​Caching.​Dependencies

Post­Sharp.​Patterns.​Caching.​Formatters

Post­Sharp.​Patterns.​Caching.​Implementation

Post­Sharp.​Patterns.​Caching.​Locking

Post­Sharp.​Patterns.​Caching.​Serializers

Post­Sharp.​Patterns.​Caching.​Value­Adapters

Post­Sharp.​Patterns.​Collections

Post­Sharp.​Patterns.​Collections.​Advices

Post­Sharp.​Patterns.​Contracts

Post­Sharp.​Patterns.​Diagnostics

Post­Sharp.​Patterns.​Diagnostics.​Adapters.​Asp­Net­Core

Post­Sharp.​Patterns.​Diagnostics.​Adapters.​Asp­Net­Framework

Post­Sharp.​Patterns.​Diagnostics.​Adapters.​Diagnostic­Source

Post­Sharp.​Patterns.​Diagnostics.​Adapters.​Http­Client

Post­Sharp.​Patterns.​Diagnostics.​Audit

Post­Sharp.​Patterns.​Diagnostics.​Backends

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Application­Insights

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Audit

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Common­Logging

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Console

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Event­Source

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Log4Net

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Microsoft

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Multiplexer

Post­Sharp.​Patterns.​Diagnostics.​Backends.​NLog

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Null

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Serilog

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Trace

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Trace­Source

Post­Sharp.​Patterns.​Diagnostics.​Contexts

Post­Sharp.​Patterns.​Diagnostics.​Correlation

Post­Sharp.​Patterns.​Diagnostics.​Custom

Post­Sharp.​Patterns.​Diagnostics.​Custom.​Messages

Post­Sharp.​Patterns.​Diagnostics.​Formatters

Post­Sharp.​Patterns.​Diagnostics.​Record­Builders

Post­Sharp.​Patterns.​Diagnostics.​Threading­Instrumentation

Post­Sharp.​Patterns.​Diagnostics.​Transactions

Post­Sharp.​Patterns.​Diagnostics.​Transactions.​Model

Post­Sharp.​Patterns.​Dynamic­Advising

Post­Sharp.​Patterns.​Formatters

Post­Sharp.​Patterns.​Model

Post­Sharp.​Patterns.​Model.​Controls

Post­Sharp.​Patterns.​Model.​Type­Adapters

Post­Sharp.​Patterns.​Recording

Post­Sharp.​Patterns.​Recording.​Operations

Post­Sharp.​Patterns.​Threading

Post­Sharp.​Patterns.​Threading.​Models

Post­Sharp.​Patterns.​Utilities

Post­Sharp.​Patterns.​Xaml

Post­Sharp.​Reflection

Post­Sharp.​Reflection.​Method­Body

Post­Sharp.​Serialization

  • Article

Class LoggingContext

Represents an execution context, typically a method or a user activity.

Namespace: PostSharp.Patterns.Diagnostics.Contexts
Assembly: PostSharp.Patterns.Diagnostics.dll
Syntax
public abstract class LoggingContext : ILoggingContext, IDisposable

Properties

Name Description
ActivationContext

Gets the LoggingContext in which the current context was activated. If the current context has been resumed, ActivationContext refers to the context in which the context was resumed.

Backend

Gets the parent LoggingBackend of the current context.

CurrentTransaction

Gets the LoggingTransaction defined or inherited by the current context.

DefinedTransaction

Gets the LoggingTransaction defined by the current context.

Description

Gets the description of the current context. The description is typically set by the LogRecordBuilder when building the opening record of a context.

EventData

Gets the LogEventData (i.e. the source of logging properties) associated with the current LoggingContext.

HierarchicalContextIdInfo

Exposes the IHierarchicalContextIdInfo for the current context. Used by SyntheticIdFormatter.

Id

Gets or set the identifier of the current context. This value is created according to the strategy set in LoggingBackend.Options.ContextIdGenerationStrategy.

IdGenerationStrategy

Gets the ContextIdGenerationStrategy used to generate the Id property for the current context.

IndentLevel

Gets or sets the indentation level for the current context.

IsAsync

Determines whether the current LoggingContext represents an async method or an asynchronous custom activity.

IsDisposed

Determines whether the current context has been disposed.

IsHidden

Determines whether the current LoggingContext is hidden. Hidden contexts may define properties but should not be rendered.

IsSharable

Determines whether the current LoggingContext can be accessed outside of its nominal lifetime (for instance after the method has completed or a custom activity has been closed). Since contexts can be pooled and reused, consumers must call the MakeSharable() method if they want to keep a reference to the LoggingContext and access it after its nominal lifetime has completed.

Kind

Gets the kind of the current context.

MemberName

Gets the name of the method or property related to the current context.

ParentContext

Gets the LoggingContext in which the current context was activated. Previously, this was the logical parent instead.

Properties

Gets the logging properties added with the associated activity.

Source

Gets the LoggingTypeSource corresponding, typically, to the declaring type of the member associated to the current context.

SyntheticId

Gets a cross-process globally unique identifier for the current LoggingContext. This value is created according to value of the LoggingBackend.Options.SyntheticIdFormatter property.

SyntheticParentId

When this property returns a non-null value, the SyntheticId property shall use the value of the SyntheticParentId property as the parent identifier, instead of recursively building the synthetic identifier based on ParentContext. You can set this property when you open a custom activity by configuring the OpenActivityOptions object.

SyntheticRootId

When this property returns a non-null value, the SyntheticId property shall return the same value as the SyntheticRootId property, instead of starting with the id of the parent context. You can set this property when you open a custom activity by configuring the OpenActivityOptions object.

ThreadContext

Gets the ThreadLoggingContext for the thread in which the current LoggingContext is currently executed.

Methods

Name Description
CreateCorrelationCookie()

Creates a cookie that can be used to correlate, using the SetCorrelation(CorrelationCookie) method, another context to the current context.

Dispose()
Dispose(bool)

Disposes the current object.

ForEachProperty(LoggingPropertyVisitor<object>, bool)

Invokes a delegate for each property defined in the current logging context and optionally in its ancestor contexts.

ForEachProperty<T>(LoggingPropertyVisitor<T>, ref T, bool)

Invokes a delegate for each property defined in the current logging context and optionally in its ancestor contexts, and specifies passes a state object to the delegate.

GetCustomRecordBuilder(ref CustomLogRecordInfo)

Gets a LogRecordBuilder for the current context to build a custom record.

GetExecutionContextData(LoggingExecutionContextData, bool)

Returns a new layer for the async stack that has this LoggingContext as the associated activity and current as the PostSharp.Patterns.Diagnostics.Contexts.LoggingExecutionContextData.Parent, if a new layer is required.

GetRecordBuilder(ref LogRecordInfo, ref LogMemberInfo)

Gets a LogRecordBuilder for the current context to build a standard record for a given method.

MakeSharable()

Allows the current context to be shared beyond its normal lifecycle by preventing it from being returned to the pool.

SetCorrelation(CorrelationCookie)

Associates the current context with another context.

SetWaitDependency(object)

Sets the wait dependency for the current context, i.e. sets a representation of what the current context is waiting for. This operation is available only in custom contexts.

ToString()
ToString(StringBuilder)

Formats a description of the current LoggingContext into a given StringBuilder.

VisitProperties(Action<string, object>, bool)

Invokes a delegate each property on the current context, and, optionally, for inherited properties in ancestor contexts. This offers a simple way to visit properties, but it has a performance overhead compared to VisitProperties<TState>(ILoggingPropertyVisitor<TState>, ref TState, in LoggingPropertyVisitorOptions) because it is weakly typed and cause the allocation of a closure class to build the action. It also does not expose the LoggingPropertyOptions.

VisitProperties<TState>(ILoggingPropertyVisitor<TState>, ref TState, in LoggingPropertyVisitorOptions)

Invokes the Visit<TValue>(string, TValue, in LoggingPropertyOptions, ref TState) method of an interface implementation for each property on the current context, and, optionally, for inherited properties in ancestor contexts.

  • Navigation

In this article

Properties

Methods