This is the fourth part of the Logging series. For your convenience you can find other parts in the table of contents in Part 1 – Correlations

We can generate correlation data on each request but we need to pass them throughout the system. Let’s start with simple REST requests.

Rest client

We want to have the following factory:

We will use it to create REST clients for communicating with our components and external services. Actual implementation could go as follows:

We use RestSharp library and we wrap it with our custom logic for client to use internally. Since we do not want to expose all the details, we adapt RestSharp with custom interface:

We expose just one function. In fact you should reimplement IRestRequest interface on your own but for the simplest implementation this is not required.

Now the basic client:

This only delegates to RestSharp client and so it is obvious.

The latter case is a bit harder. We need to pass headers to the request and parse the response:

So we send correlation ID and logical time to the service and on return we parse logical time and update it in correlator. Simple as that.

Service bus

We also need to pass correlation data to service bus messages. We can store them in metadata:


We now pass correlation data throughout the system. The only missing piece is parsing logs. We will handle this next time.