记录基于.net控制台的应用程序的调用堆栈. [英] Logging Call Stack for .net console based applications.

查看:48
本文介绍了记录基于.net控制台的应用程序的调用堆栈.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为基于控制台的应用程序记录调用堆栈中的所有帧?

我知道以下代码:

How to log all frames in a call stack for a console based application?

I am aware of this code:

StackTrace stackTrace = new StackTrace(); // get call stack
StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames)
stackFrame.GetMethod().Name;


但是我想记录所有正在执行的方法,并记录函数的开始和函数的结束.

我们有大量的文件和方法,并且我希望以最小的更改记录启动和记录.在不触及实际方法的情况下结束功能.

如果我们可以编写单独的接口,而仅在主函数中编写一条语句,那将有很大的帮助.

任何建议将不胜感激.


But I want to log all the methods that are being executed and log the start of the function and end of the function.

We have lots of files and methods and with a minimal change i wish to log the start & end of functions without touching the actual methods.

If we can write seperate interface and just a statement in the main function it would be of great help.

Any suggestions would be appreciated.

推荐答案

您应该研究面向方面的编程(AOP). Spring.NET中有一个可用的实现.请在Google中搜索"Spring.NET AOP".
AOP允许您通过使用before和after选项等进行配置,将代码注入方法中!
问候,

—曼弗雷德(Manfred)
You should look into Aspect Oriented Programming (AOP). There''s an implementation available in Spring.NET. Please google "Spring.NET AOP".
AOP lets you inject code into methods via configuration with before and after options etc. !

Regards,

— Manfred


这篇关于记录基于.net控制台的应用程序的调用堆栈.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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