Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

Tracing and Method Names

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jay Pondy - 06 Mar 2006 19:35 GMT
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
Cowboy (Gregory A. Beamer) - MVP - 07 Mar 2006 16:08 GMT
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!

Signature

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

***************************
Think Outside the Box!
***************************

> 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
[quoted text clipped - 10 lines]
>   T.TraceEvent(TraceEventType.Stop, 0, "MethodA")
> End Sub
Jay Pondy - 09 Mar 2006 20:12 GMT
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?

>One options (poor mans option):
>
[quoted text clipped - 14 lines]
>
>Hope this helps!
Jay Pondy - 08 Mar 2006 12:06 GMT
Use System.Reflection.MethodInfo.GetCurrentMethod.Name

>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
[quoted text clipped - 10 lines]
>  T.TraceEvent(TraceEventType.Stop, 0, "MethodA")
>End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.