Mat*_*att 4 .net c# performance logging
我已经在很多类中编写了一个包含许多方法的大型C#应用程序.
我正在尝试记录所调用的内容以及在开发过程中的频率.(我在数据库中记录)
每个方法都填充以下调用:
void myMethod()
{
log(entering,args[]);
log(exiting,args[]);
}
Run Code Online (Sandbox Code Playgroud)
因为我想对我的所有方法都这样做,有没有更好的方法来执行此操作,然后必须在每个方法中复制这些代码行?
这是他们头版的第一个例子:
public class TraceAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionEventArgs eventArgs)
{ Trace.TraceInformation("Entering {0}.", eventArgs.Method); }
public override void OnExit( MethodExecutionEventArgs eventArgs)
{ Trace.TraceInformation("Leaving {0}.", eventArgs.Method); }
}
Run Code Online (Sandbox Code Playgroud)
似乎正是您所需要的!