是否有可能得到参数值在调用堆栈在.NET中的每一帧 [英] Is it possible to get parameters' values for each frame in call stack in .NET

查看:234
本文介绍了是否有可能得到参数值在调用堆栈在.NET中的每一帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我说的是管理的.NET code。 如果我们运行任何程序,并附VS它我们可以看到参数值在调用堆栈中每个方法。 我想创建一个记录解决方案,这将记录所有参数值在调用堆栈每个方法。其实我需要这个信息的情况下发生异常。

I'm talking about managed .NET code. If we run any program and attach VS to it we can see parameters' values for each method in call stack. I'd like to create a logging solution which will log all parameters' values for each method in call stack. Actually I need this info in case an exception occurs.

我知道这是可能的分析API。但我不知道是否有可能只用管理code?

I know it's possible with profiling API. But I wonder is it possible with only managed code?

更新:好吧,可能与纯.NET这是不可能的。然后,可能是某种非托管code ...重点是从内部应用程序本身做到这一点。在发生异常可能会调用一些库的应用程序(可能非托管),它返回有关调用堆栈方法值的信息。只是想法......

UPDATE: Ok, probably with pure .NET it's impossible. Then may be with some kind of unmanaged code... the point is to do this from within application itself. An application in case of an exception could call some library (may be unmanaged) which returns info about methods' values in call stack. Just thoughts...

推荐答案

参数。事实上,他们没有记录/登录可言,除非你选择明确地做到这一点。

Parameters values aren't stored in StackFrame instance. In fact, they aren't recorded/logged at all, unless you choose to do it explicitly.

一个显而易见的方法来记录论文值是使用AOP。这当然将意味着成本,但在与日志框架和右日志级别相结合,它可以是一种选择。您也可以选择仪器在你的基地code,其中的例外是更可能抛出异常,只有某些类型/方法。我可能会选择Postsharp其静态织造能力,发出日志调用。

One obvious way to log theses values is to use AOP. It would certainly imply a cost, but in conjunction with a logging framework and the right log level, it may be an alternative. You could also choose to instrument only some types/methods in your basecode, where exceptions are more likely to be thrown. I would probably choose Postsharp for its static weaving capabilities, to emit log calls.

无论如何,它远远不是一个理想的解决方案,但我怕你不会有很多选择,如果你陷在管理世界。

Anyway, it's far from being an ideal solution, but I'm afraid you won't have many options if you're stuck in the managed world.

这篇关于是否有可能得到参数值在调用堆栈在.NET中的每一帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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