PC Review


Reply
Thread Tools Rate Thread

Application Logging and Class.Method Names

 
 
Jay Pondy
Guest
Posts: n/a
 
      27th Jun 2005
While logging or tracing an application I frequently need to know
where the code is executing - the class.method name.

One way to obtain this information is:

Me.GetType.Name & "." &
System.Reflection.MethodInfo.GetCurrentMethod.Name

The problem with this is that if you need to use it numerous times in
a method it makes the code look awfully messy.

Another approach would be to define a method level variable and set it
at the start of the method - the trouble with this is that it executes
every time the method is called. You could add an if statement to
test the tracing variable but again this makes the code look messy.

I am curious as to how others may have solved this problem.

Ideally what I would like is a tracing call like:

Trace.WritelineIf(Switch.TraceVerbose, SomeClass.FormatMessage("My
Tracing Message")

where the FormatMessage routine could determine the method signature
of the caller and format a string to include the date, time, thread,
and class.method followed by the Message.

Using the StackFrame it is possible to get at the callers method name
but not it's class name.

Any ideas?

I've looked at the Microsoft Application Logging Block but for some
reason this information (Class.Method) is not part of what they log.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[CF 2.0] How to properly exit a console application from a method in a class ? Steve B. Microsoft Dot NET Compact Framework 4 21st Aug 2006 04:41 PM
call a mnuFileNew_Click method from a Main MDI class from another class (can be a MdiChild class.. )? M. G, Microsoft Dot NET Framework Forms 1 31st May 2006 06:28 AM
When to Qualify Interface Method Names in an Implementation class Kevin Frey Microsoft C# .NET 2 20th Jan 2006 09:49 AM
Inheritance problem - Base Class method being called when Derived Class method should be called. Jeff Molby Microsoft VB .NET 3 6th Mar 2005 11:03 PM
Sharing class between web application and windows application - what is best method? James Radke Microsoft VB .NET 2 26th Dec 2003 06:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:38 PM.