Is LogicalOperationStack incompatible with async in .Net 4.5

前端 未结 3 1394
萌比男神i
萌比男神i 2021-02-04 04:16

Trace.CorrelationManager.LogicalOperationStack enables having nested logical operation identifiers where the most common case is logging (NDC). Should it still work

3条回答
  •  执笔经年
    2021-02-04 04:38

    One of the solutions mentioned here and on the web is to call LogicalSetData on context:

    CallContext.LogicalSetData("one", null);
    Trace.CorrelationManager.StartLogicalOperation();
    

    But in fact, just reading current execution context is enough:

    var context = Thread.CurrentThread.ExecutionContext;
    Trace.CorrelationManager.StartLogicalOperation();
    

提交回复
热议问题