How is a multi-threaded cross-tier singleton with a correlation identifier without blocking?

Thus, we use a single state context context with a correlation identifier for centralized logging. The goal is to track the identifier throughout our process and map different levels.

Access to the state context is done by several DLLs and several users.

The difficulty arises when multithreading comes into play:

  • Process 1 started by user 1
  • The correlation identifier is set to {1}
  • DLL A gets the state context and gets the correlation identifier {1}
  • Until process 1 is complete, process 2 is fired by user 2
  • The correlation identifier is set to {2}
  • DLL B from the context of the state of access to the process with the correlation identifier {2}, when it should be {1}

How to solve this problem?

We do not perceive blocking as our decision? Any other ideas?

Here is a chart

        (S)->[  CorrelationID {get;set}  ]                  
               ^           ^            ^
    U1 <-->    |           |            |                 O  
    U2 <--> [DLLA] <-->  [DLLB] <-->  [DLLC]       <-->  | |
    U3 <-->         
            {Web}  <--> {Domain} <-> {Data Access} <--> {DB}

    (<--                 Process / Thread           -->    )  

{} = Examples of possible DLLs

Each user process must have 1 correlation identifier

+4
source share
2 answers

After much research, we found a solution.

We use the LogicalCallContext Class in the .Net Framework

So what the LogicalCalContext class does, it uses the .Net Framework, it stores key values ​​in the pool, retaining a callback, even if it jumps the stream.

, ...

NLog WebAPI

Serilog, .

0

Source: https://habr.com/ru/post/1609370/


All Articles