Debug Statements - writing to the console and files
-
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 :)
-
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 :)
Wrap them in #if DEBUG blocks.
#if DEBUG
Console.WriteLine("Debugging");
#endifDave
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) -
Wrap them in #if DEBUG blocks.
#if DEBUG
Console.WriteLine("Debugging");
#endifDave
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)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. -
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 :)
Member 5646867 wrote:
However, the time will come when I want to remove all such calls.
Replace
Console.Writeline
withDebug.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
-
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 :)
Thanks for all your answers - I'll look into each of the suggestions :)
-
Member 5646867 wrote:
However, the time will come when I want to remove all such calls.
Replace
Console.Writeline
withDebug.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
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 -
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, 2008Yup. 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