Table of Contents

Class LogicalThreadContext

Namespace
log4net
Assembly
log4net.dll

The log4net Logical Thread Context.

public sealed class LogicalThreadContext
Inheritance
LogicalThreadContext
Inherited Members

Examples

Example of using the thread context properties to store a username.

        <pre><code class="lang-csharp">LogicalThreadContext.Properties["user"] = userName;

log.Info("This log message has a LogicalThreadContext Property called 'user'");

Example of how to push a message into the context stack

        <pre><code class="lang-csharp">using(LogicalThreadContext.Stacks["LDC"].Push("my context message"))

{ log.Info("This log message has a LogicalThreadContext Stack message that includes 'my context message'");

} // at the end of the using block the message is automatically popped

Remarks

The LogicalThreadContext provides a location for System.Runtime.Remoting.Messaging.CallContext specific debugging information to be stored. The LogicalThreadContext properties override any ThreadContext or GlobalContext properties with the same name.

The Logical Thread Context has a properties map and a stack. The properties and stack can be included in the output of log messages. The PatternLayout supports selecting and outputting these properties.

The Logical Thread Context provides a diagnostic context for the current call context. This is an instrument for distinguishing interleaved log output from different sources. Log output is typically interleaved when a server handles multiple clients near-simultaneously.

The Logical Thread Context is managed on a per System.Runtime.Remoting.Messaging.CallContext basis.

The System.Runtime.Remoting.Messaging.CallContext requires a link time System.Security.Permissions.SecurityPermission for the Infrastructure. If the calling code does not have this permission then this context will be disabled. It will not store any property values set on it.

Properties

Properties

The thread properties map

public static LogicalThreadContextProperties Properties { get; }

Property Value

LogicalThreadContextProperties

The thread properties map

Remarks

The LogicalThreadContext properties override any ThreadContext or GlobalContext properties with the same name.

Stacks

The thread stacks

public static ThreadContextStacks Stacks { get; }

Property Value

ThreadContextStacks

stack map

Remarks

The logical thread stacks.