Tracing and Method Names

  • Thread starter Thread starter Jay Pondy
  • Start date Start date
J

Jay Pondy

In the example below where the TraceEvent method is being called how
can I get the Methods name ("MethodA") I am passing as the message
dynamically?

It is a real pain to have to copy the methods name repeatedly into my
tracing code. Surely there is some way to use the tracing system
where it can automatically put the method name into the tracing stream
for me. No?

Private Sub MethodA()
T.TraceEvent(TraceEventType.Start, 0, "MethodA")
Some code...
T.TraceEvent(TraceEventType.Stop, 0, "MethodA")
End Sub
 
One options (poor mans option):

Private Sub MethodA()
Dim m As String = "MethodA"

T.TraceEvent(TraceEventType.Start, 0, m)
Some code...
T.TraceEvent(TraceEventType.Stop, 0, m)
End Sub

This at least sets the value the same and allows some code generation across
all methods for the m value. It gets expensive to set up a monitor to
determine which method you are in, esp. if you are hitting it numerous times,
so I would be wary about that direction. You could set m at runtime using
that form of method, but typing the line once for each method, or autogenning
for methods, is a much more practical approach.

Hope this helps!

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Thanks Greg.

I was beginning to think I had the plague or something.

Another method I've found is to pop it off the stack which includes
the Class.MethodName which is what I am really after.

I write a lot of industrial code which needs to be 24x7 and tracing
can really be a life saver because all kinds of crazy things happen to
network connections, partial file transfers etc. etc.

If you see this can you tell me if I am showing up as an MSDN Managed
Newsgroup member?
 
Back
Top