Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Enter/Leave debug methods?

Enter/Leave debug methods?

Scheduled Pinned Locked Moved C#
debuggingquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jim Turner 0
    wrote on last edited by
    #1

    Are there any methods available in Diagnostics or other class that will output the function name when it is entered/left? I need to trace execution through some spaghetti code I've inherited, and I'm hoping to avoid hand-coding enter/leave WriteLines.

    A L D 3 Replies Last reply
    0
    • J Jim Turner 0

      Are there any methods available in Diagnostics or other class that will output the function name when it is entered/left? I need to trace execution through some spaghetti code I've inherited, and I'm hoping to avoid hand-coding enter/leave WriteLines.

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      You could use the debug method. For more information, see here[^].

      Me, I'm dishonest. And a dishonest man you can always trust to be dishonest.
      Honestly. It's the honest ones you want to watch out for...

      1 Reply Last reply
      0
      • J Jim Turner 0

        Are there any methods available in Diagnostics or other class that will output the function name when it is entered/left? I need to trace execution through some spaghetti code I've inherited, and I'm hoping to avoid hand-coding enter/leave WriteLines.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Hi, Something like this should do the trick;

        System.Diagnostics.Debug.WriteLine(
        new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name);

        or, if you wanted to put this in a utility funtion;

        public static string GetCurrentMethodName()
        {
        // Aight, not the current one, but we're actually interested in the
        // name of the name of the previous method (0+1 in the list)
        return new System.Diagnostics.StackTrace().GetFrame(1).GetMethod().Name;
        }

        You've already looked at log4net? I found it to be a real help, combined with OneNote :)

        I are Troll :suss:

        1 Reply Last reply
        0
        • J Jim Turner 0

          Are there any methods available in Diagnostics or other class that will output the function name when it is entered/left? I need to trace execution through some spaghetti code I've inherited, and I'm hoping to avoid hand-coding enter/leave WriteLines.

          D Offline
          D Offline
          David Skelly
          wrote on last edited by
          #4

          You might find Spring.NET's AOP support useful. I've used the Java equivalent, but not the .NET version. It allows you to instrument existing code to add functionality such as you describe, without having to change the existing source. I don't really like AOP but it can be useful for situations like this.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups