I use the TraceSource class for logging in my .NET projects.
However a point that has never been clear to me is, what the intent of the id
parameter in the TraceEvent
method. Currently, I always set it to 0.
But what is the expected or typical useful usage of it?
I can think of a few possibilities:
TraceEventType.(Start|Stop|Suspend|Resume|Transfer)
enumeration values;I've asked myself the same question and I didn't found anything to clarify this in any Microsoft documentation. What I've manage to find is an article written by a Microsoft MVP, Richard Grimes: "The id parameter is whatever you choose it to be, there is no compulsion that a particular ID is associated with a particular format message." He uses 0, for the id argument, in all examples.
In MSDN articles, I've seen it used random, not providing any additional info. I believe that you can use in any way that helps you best when reading the logs, as long as you maintain the same code convention. It may prove useful afterwards in trace filtering, if you want to use the SourceFilter.ShouldTrace method, that accept an id argument too.
I use it to describe the error type, if I have an error, or use 0 for anything else.