Correlation Ids — Log4net Enrichment

The Goal — Correlation Ids in Logs

We collect logs throughout our applications, they are sent to an HTTP endpoint at Sumologic, meaning we can browse and search through all these logs in the same place.

Initial Introduction of Correlation Ids

We’ve recently added correlation ids to our back-end microservices’ loggers. For those services, which are running as Azure Functions, we initially wrote our own logging class to POST messages to Sumo, so it was relatively easy to inject a per-request scoped service into our IoC container which would generate the correlation id and inject that into the (transient) loggers injected into each resolved service instance, so that every log written by the operation would use the same correlation id.

How Does This Help?

For all our microservice logs, we can see each request in isolation now in the logs. This is way more helpful that just a sea of log messages, and it means we can add additional informational or debugging logs to the system and know that we’ll be able to read those logs back in context rather than in isolation — this makes our logs way more useful in themselves.


Because the correlation id is injected manually into the messages, including correlation ids with all our page requests in the website would be a large undertaking. It would be better if there were a way to configure our logging framework (we’re using log4net right now) to include the correlation id automatically. If we could do that, all our logs would have correlation ids in and we wouldn’t need to make changes to individual pages in order to achieve that.


Correlation Ids are hugely useful tools for develops and support engineers to get value out of logging and monitoring tools, and also to add confidence and certainty to interactions with customers.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store