Shared Correlation ID with Castle (Windsor) LoggingFacility

339 Views Asked by At

I'm using Castle Windsor and Log4Net and I want to share "correlation IDs" between different services (per transaction/WCF call). Ideally, this would even span over WCF transactions (a click on the client side generates the ID which is then reused on the server).

It looks like IExtendedLogger and its ThreadProperties are the way to go, but how would I set those? Is there a better way than creating my own ILoggerFactory and setting the ThreadProperties upon creation? (Btw, could different LifeStyle settings for the services break the mechanism?)

The docs are unfortunately really sparse... :(

My goal is that my logs would look like this:

1111-1111-1111-1111 INFO OrderService: Processing order with ID 8765
8888-8888-8888-8888 INFO CustomerService: Updating address for customer with ID 9999
1111-1111-1111-1111 INFO OrderRepository: Loading order with ID 1234
1111-1111-1111-1111 INFO CustomerRepository: Loading customer with ID 2222
8888-8888-8888-8888 INFO CustomerRepository: Loading customer with ID 2222
...

So this would be two different transactions (entry points in OrderService and CustomerService), and even though both use the CustomerRepository (dependency), the context would be kept, so that it would be easy to see which log message belongs to which call/transaction.

0

There are 0 best solutions below