I want to log every request xml message in my WCF service project to database. Please suggest me which is the best and preferred approach.
1) Using idispatchmessageinspector interface
OR
2) writing Custom SQL database trace listener?
I want to log every request xml message in my WCF service project to database. Please suggest me which is the best and preferred approach.
1) Using idispatchmessageinspector interface
OR
2) writing Custom SQL database trace listener?
You would have to write a custom WCF Trace Listener.
Look here for some help: http://www.enusbaum.com/blog/2007/05/19/creating-a-custom-listener-for-your-wcf-application-in-c/ and http://weblogs.thinktecture.com/cweyer/2009/06/custom-tracelistener-writing-trace-messages-to-the-net-services-service-bus.html
The best approach usually depends on various factors, but in your case it seems that using message inspectors would be a preferred approach as this is what it was build for i.e to capture WCF messages and do whatever you want do with them.
SQL trace is to trace SQL messages (communication between SQL server and SQL client applications) and not WCF messages.
I think using idispatchmessageinspector
interface and use ThreadPool.QueueUserWorkItem()
to read the request and log into database in AfterReceiveRequest
event will be better when compared to using Tracing. I feel Tracing may be have some overhead as it is meant for some diagonistic purposes and do not want to enable tracing in prod permanently.
Is there any issues using idispatchmessageinspector
and ThreadPool.QueueUserWorkItem()
for logging the request message to database?
Thanks!
Bala