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. Debug Statements - writing to the console and files

Debug Statements - writing to the console and files

Scheduled Pinned Locked Moved C#
debugginghelptutorialquestionannouncement
7 Posts 5 Posters 2 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.
  • S Offline
    S Offline
    stormydaniels
    wrote on last edited by
    #1

    Hi, I'm writing an application in which I'm currently using Console.Writeline() calls to output the various stages. This helps me to develop and debug as I go. However, the time will come when I want to remove all such calls. Can anyone suggest some advice, an article (I have searched on CP) or other source which will tell me how to use debug statements in code which I can then switch off for release. I was thinking of a logging class - in debug mode it would write to the console but in release mode it would write certain information to a file. The Console.Writeline() methods allows me to do the following: Console.Writeline("Val1 {0}, Val2 {2}", val1, val2); How could I write my own function which would accept an unknown number of parameters like this? I would like my function to pass the parameters directly to Console.Writeline() or to a file depending on a flag. Thanks for any help offered :)

    D P S 3 Replies Last reply
    0
    • S stormydaniels

      Hi, I'm writing an application in which I'm currently using Console.Writeline() calls to output the various stages. This helps me to develop and debug as I go. However, the time will come when I want to remove all such calls. Can anyone suggest some advice, an article (I have searched on CP) or other source which will tell me how to use debug statements in code which I can then switch off for release. I was thinking of a logging class - in debug mode it would write to the console but in release mode it would write certain information to a file. The Console.Writeline() methods allows me to do the following: Console.Writeline("Val1 {0}, Val2 {2}", val1, val2); How could I write my own function which would accept an unknown number of parameters like this? I would like my function to pass the parameters directly to Console.Writeline() or to a file depending on a flag. Thanks for any help offered :)

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      Wrap them in #if DEBUG blocks.

      #if DEBUG
      Console.WriteLine("Debugging");
      #endif

      Dave
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
      Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

      E 1 Reply Last reply
      0
      • D DaveyM69

        Wrap them in #if DEBUG blocks.

        #if DEBUG
        Console.WriteLine("Debugging");
        #endif

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

        E Offline
        E Offline
        Ennis Ray Lynch Jr
        wrote on last edited by
        #3

        or System.Diagnostics.Debug.Write with appropriate listeners.

        Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
        Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
        Most of this sig is for Google, not ego.

        1 Reply Last reply
        0
        • S stormydaniels

          Hi, I'm writing an application in which I'm currently using Console.Writeline() calls to output the various stages. This helps me to develop and debug as I go. However, the time will come when I want to remove all such calls. Can anyone suggest some advice, an article (I have searched on CP) or other source which will tell me how to use debug statements in code which I can then switch off for release. I was thinking of a logging class - in debug mode it would write to the console but in release mode it would write certain information to a file. The Console.Writeline() methods allows me to do the following: Console.Writeline("Val1 {0}, Val2 {2}", val1, val2); How could I write my own function which would accept an unknown number of parameters like this? I would like my function to pass the parameters directly to Console.Writeline() or to a file depending on a flag. Thanks for any help offered :)

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #4

          Member 5646867 wrote:

          However, the time will come when I want to remove all such calls.

          Replace Console.Writeline with Debug.Writeline... If you do a Release build, the calls to the Debug.Writeline should not be included in the executable.

          "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

          modified on Tuesday, November 18, 2008 2:38 PM

          D 1 Reply Last reply
          0
          • S stormydaniels

            Hi, I'm writing an application in which I'm currently using Console.Writeline() calls to output the various stages. This helps me to develop and debug as I go. However, the time will come when I want to remove all such calls. Can anyone suggest some advice, an article (I have searched on CP) or other source which will tell me how to use debug statements in code which I can then switch off for release. I was thinking of a logging class - in debug mode it would write to the console but in release mode it would write certain information to a file. The Console.Writeline() methods allows me to do the following: Console.Writeline("Val1 {0}, Val2 {2}", val1, val2); How could I write my own function which would accept an unknown number of parameters like this? I would like my function to pass the parameters directly to Console.Writeline() or to a file depending on a flag. Thanks for any help offered :)

            S Offline
            S Offline
            stormydaniels
            wrote on last edited by
            #5

            Thanks for all your answers - I'll look into each of the suggestions :)

            1 Reply Last reply
            0
            • P Paul Conrad

              Member 5646867 wrote:

              However, the time will come when I want to remove all such calls.

              Replace Console.Writeline with Debug.Writeline... If you do a Release build, the calls to the Debug.Writeline should not be included in the executable.

              "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

              modified on Tuesday, November 18, 2008 2:38 PM

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              I don't know about that. I would think the calls to Debug.WriteLine, or anything else in the Debug class, would be left out though. Console, I think, stays around, even though it's a Windows Forms app.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008

              P 1 Reply Last reply
              0
              • D Dave Kreskowiak

                I don't know about that. I would think the calls to Debug.WriteLine, or anything else in the Debug class, would be left out though. Console, I think, stays around, even though it's a Windows Forms app.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008

                P Offline
                P Offline
                Paul Conrad
                wrote on last edited by
                #7

                Yup. It is the Debug class. Got my wires crossed there for a moment :laugh:

                "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                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