We all know it's perfectly ok to marry up WCF with PIAB to address cross cutting concerns like logging, validation, auditing etc (visit http://msdn.microsoft.com/en-us/magazine/cc136759.aspx).
But the bog standard log call handler only support a limited set of "extended properties" for the logs. What if there are requirements for additional information to be logged such as: client Ip address, user id etc?
Answer (will be added as an answer later due to stackoverflow's strange policy on members with low ratings):
After much digging around I came up with this solution which I hope will benefit others with the same query.
First of all, you need to have a custom call handler to include all the additional data you want for your logs. You can refer to the entlib source code and look for LogCallHandler. Add the additional data in GetLogEntry private method:
After thatn, you have to creat the infrastruture to propagate context data from client to server. I have a wrapper class for CallContext to store a dictionary object for context data:
On the service client, this context will be added to the request message header through implementing IClientMessageInspector.
On the service side, I have a custom implementation of ICallContextInitializer to retrieve the message header from the incoming message and set it back to the outgoing message:
This essentially is a round trip for the message header payload to travel. In the AfterInvoke method, the message header could be modified before being sent back. Finally, I have created an endpoint behaviour to apply the MessageInspector and CallContextInitializer.
You could also write a contract behaviour to achieve the same by decorating your service/contract with the behaviour attribute.
Now from your service client, you can set all the context data like below:
This is also posted on the discussion board of entlib.codeplex at: http://entlib.codeplex.com/discussions/266963