Bite my bytes

What I learn by day I blog at night - A blog from Microsoft Consultant working from Ljubljana, Slovenia

  Home :: Contact :: Syndication  
  999 Posts :: 7691 Comments :: 235 Trackbacks


Most popular posts
in last 360 days


My Projects



Copyright © by David Vidmar
Contact me!
LinkedIn Profile

I was fiddling with some prototype code today and I needed very simple logging to spot an error. So I threw together this:

private static void WriteLog(string message)
    StreamWriter sw = new StreamWriter("test.log");
    sw.WriteLine(DateTime.Now.ToString("yy-MM-dd HH:mm:ss - " + message)); 

But the result was not exactly what I expected. My program speaks some kind of l33t!

07-07-04 15:21:31 - Sarup.
07-07-04 15:21:31 - Para21eer31: repo31ior7 = D:.Subver31ion.repo31.DevelopinA.D., revi31ion = 137627, o = 4avi4.vi421ar@a4aca.31i
07-07-04 15:22:06 - Ti22eoue4!

How fast can you spot the bug?

It took me more than a few seconds... But maybe just because this is the coolest log I ever wrote.

Posted on Wednesday, July 04, 2007 3:35 PM | Filed under: Developement |


# re: Fun little bug 7/4/2007 4:14 PM Mladen
l337 with datatime formatting!

what could be better :)))

# re: Fun little bug 7/4/2007 5:52 PM Pat
Did you copy paste from the log file?
How did you get an underscore on the second line between the month and day ?

# re: Fun little bug 7/4/2007 6:04 PM David
I copy/pasted and cleaned up. The underscore was a typo. Fixed. The problem is with the spelling. I wanted to put regular words in my log, words like "repository", "Developing" and ended with l33t speak.

# re: Fun little bug 7/4/2007 7:41 PM david
i believe it should be like this

sw.WriteLine(DateTime.Now.ToString("yy-MM-dd HH:mm:ss - ") + message);

# re: Fun little bug 7/4/2007 7:50 PM David
Bulls eye, D!

# re: Fun little bug 7/5/2007 8:26 PM jayson knight
In most cases, string.Format is your friend and probably would have saved you from this bug:

string.Format("{0} - {1}", DateTime.Now.ToString("yy-MM-dd HH:mm:ss"), message);

# re: Fun little bug 7/5/2007 9:16 PM David
Yeah, sure. I use it all the time. But since it kind of pain to writte a string.Format formatet strings (!) I usually just concatenate with + and them do a quick refactor with ReSharper that suggests that I should use string.Format. It's real time saver.

Comments have been closed on this topic.