Reputation: 27608
When using System.Diagnostics TraceSource for logging/tracing, is there a difference between using TraceSource.TraceTransfer and TraceSource.TraceEvent(TraceEventType.Transfer, ... ?
In our environment, we will be developing a number of services that will communicate via WCF. We are also evaluating what platform we should use for logging/tracing. We are leaning towards using System.Diagnostics, at least in part because of the ability to correlate logs between services using the CorrelationManager, ActivityID, TraceTransfer etc.
I can see in the documentation for TraceSource that it has a TraceTransfer method as well as a TraceEvent that can take TraceEventType.Transfer as an event type. When would you use one vs the other? I have seen examples like here that show how to use Start/Stop and how to manage the ActivityID and CorrelationManager, but I have rarely seen anyone use TraceSource.TraceEvent(TraceEventType.Transfer, ... ). There is an example here that shows using TraceEventType.Transfer (as well as explicitly calling TraceTransfer).
By this point, maybe I am actually starting to answer my own question...
It seems like TraceSource.TraceTransfer is explicitly doing something with the ActivityID that is passed as a parameter whereas calling TraceSource.TraceEvent(TraceEventType.Transfer, ...) is not explicitly doing anything with the ActivityID (since it is not passed as a parameter). It seems like it is really just logging another event, that happens to be a Transfer event, but does not do anything else with the CorrelationManager or anything else.
Thanks for any help.
Upvotes: 2
Views: 4462
Reputation: 27608
According to the MSDN documentation for TraceSource.TraceTransfer, TraceSource.TraceTransfer calls TraceListener.TraceTransfer. The base implementation of TraceListener.TraceTransfer simply calls TraceListener.TraceEvent(TraceEventType.Transer, ...), passing a string representation of the guid passed to TraceSource.TraceTransfer.
So, it seems to me that TraceSource.TraceTransfer provides way to explicitly indicate that an activity transfer is happening. At the call site, it is more obvious and more typesafe to use TraceSource.TraceTransfer. If implementing a TraceListener, you could take advantage of the explicit TraceTransfer call and the fact that the activity id is passed in as a Guid to do any special work that you want to do when an activity id is transferred.
Upvotes: 2