Click here to Skip to main content
11,641,971 members (60,376 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 C#4.0
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.
Posted 8-Sep-12 8:14am
Edited 8-Sep-12 8:17am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 285
1 Sergey Alexandrovich Kryukov 159
2 Afzaal Ahmad Zeeshan 145
3 OriginalGriff 110
4 Mika Wendelius 90
0 Mika Wendelius 460
1 DamithSL 353
2 OriginalGriff 315
3 Sergey Alexandrovich Kryukov 179
4 Afzaal Ahmad Zeeshan 169


Advertise | Privacy | Mobile
Web01 | 2.8.150731.1 | Last Updated 8 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100