NDC PushFormat Method | Apache log4net™ SDK Documentation

Pushes a new context message.

Namespace: log4net
Assembly: log4net (in log4net.dll) Version: 2.0.8.0-.NET 4.0
Syntax

C#
VB
C++
F#
Copy

    public static IDisposable PushFormat(
    	string messageFormat,
    	params Object[] args
    )

    Public Shared Function PushFormat (
    	messageFormat As String,
    	ParamArray args As Object()
    ) As IDisposable

    public:
    static IDisposable^ PushFormat(
    	String^ messageFormat,
    	... array<Object^>^ args
    )

    static member PushFormat :
            messageFormat : string *
            args : Object[] -> IDisposable

#### Parameters

messageFormat
  Type: System
  String
  The new context message string format.
args
  Type:
  System
  Object
  Arguments to be passed into messageFormat.

#### Return Value

Type: IDisposable
An IDisposable that can be used to clean up the context stack.
Remarks

Note
The NDC is deprecated and has been replaced by the Stacks. The current NDC implementation forwards to the ThreadContext.Stacks["NDC"].

Pushes a new context onto the context stack. An IDisposable is returned that can be used to clean up the context stack. This can be easily combined with the using keyword to scope the context.

Examples

Simple example of using the Push method with the using keyword.
C#
Copy

    var someValue = "ExampleContext"
    using(log4net.NDC.PushFormat("NDC_Message {0}", someValue))
    {
        log.Warn("This should have an NDC message");
    }

See Also

#### Reference

NDC Class
log4net Namespace