Attribute Based Programming - Tracing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm interested in building a component that will be used to trace an
application with minimal coding. The applications we build are typically we
applications. The trace and debug classes offer some of this functionality,
but I'm looking for something that a little cleaner to impliment. I've come
across several articles discussing Aspect Oriented Programming techiniques,
which in .net appear to require inheritiing from ContextBoundObject. This
idea is very appealing, in that by applying several custom attributes to a
class I can capture method names and the parameters being passed in only by
applying attributes at run time. The down side is that each class needs to
inherit from ContextBoundObject, which severly limits my ability to inheret
from anything else.

Does anyone have any alternative ideas that would allow me to inspect the
values of parameters being passed into a method at run time? The key piece
here is that our application are typically web apps.
 
I use reflection:

public static void log(string s)
{

StackTrace stackTrace = new StackTrace();
StackFrame stackFrame = stackTrace.GetFrame(1);
MethodBase methodBase = stackFrame.GetMethod();

Trace.WriteLine(DateTime.Now+":"+methodBase.Name+":"+s);
}
 
John,

Thanks for the suggestion. This allows me to easily get the method name. I
was wanting to capture the method name and any parameter values being passed
into the method. I haven't found any ways to do that.

Ken
 
Back
Top