When to use 'nested diagnostic context' (NDC)?

后端 未结 4 758
情深已故
情深已故 2020-12-07 18:46

Playing with log4net, I have seen the possibility to use a per-thread stack of context labels called the NDC.

The labels pushed on this stack are displayed in a Pat

4条回答
  •  独厮守ぢ
    2020-12-07 19:19

    NDC.Push has been deprecated. The preferred way now (ThreadContext.Stacks["NDC"]) is this:

    var disposable = ThreadContext.Stacks["NDC"].Push("context");
    try
    {
      Log.Info("begin"); // optional, but nice
      ...
    }
    finally
    {
      Log.Info("end"); // optional, but nice
      disposable.Dispose();
    }
    

    Remember to check your conversion pattern so that it includes %property{NDC}:

    
      
    
    

提交回复
热议问题