By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,965 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,965 IT Pros & Developers. It's quick & easy.

Application Logging and Class.Method Names

P: n/a
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.

Jul 22 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.