如何向 C# 中的每个方法调用添加 Trace()? [英] How can I add a Trace() to every method call in C#?

查看:19
本文介绍了如何向 C# 中的每个方法调用添加 Trace()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难追踪锁定问题,所以我想记录每个方法调用的进入和退出.我以前用 C++ 做过这个,而不必向每个方法添加代码.这可以用 C# 实现吗?

I am having a hard time tracking down a lock issue, so I would like to log every method call's entry and exit. I've done this before with C++ without having to add code to every method. Is this possible with C#?

推荐答案

可能最好的办法是使用 AOP(面向方面​​的编程)框架在方法执行前后自动调用跟踪代码.AOP 和 .NET 的流行选择是 PostSharp.

Probably your best bet would be to use an AOP (aspect oriented programming) framework to automatically call tracing code before and after a method execution. A popular choice for AOP and .NET is PostSharp.

这篇关于如何向 C# 中的每个方法调用添加 Trace()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆