DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
A .NET Tracing Attribute
// a simple way to trace method execution.
//
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property,
AllowMultiple = false)]
public class CallTracingAttribute : Attribute
{
public CallTracingAttribute()
{
#if TRACE
try
{
StackTrace stackTrace = new StackTrace();
StackFrame stackFrame = stackTrace.GetFrame(1);
Trace.TraceInformation("{0}->{1} {2}:{3}",
stackFrame.GetMethod().ReflectedType.Name,
stackFrame.GetMethod().Name,
stackFrame.GetFileName(),
stackFrame.GetFileLineNumber());
}
catch
{
}
#endif
}
}





