Tracing and Method Names

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
 
G

Guest

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!
***************************
 
J

Jay Pondy

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top