# Simplest WP7 logger

Just ended up with this approach for wp7 (no tag yet), in case someone would find it useful. Also, improvement considerations are welcome.

It works with

• SimpleLogger.WriteLine("JustLine");
• SimpleLogger.WriteLine(ObjectToBeCastedToString);
• SimpleLogger.WriteLine("Price is {0} {1}", price, currency);
public class SimpleLogger
{
private static DateTime lastLog;

[Conditional("DEBUG")]
public static void WriteLine(object value)
{
WriteLine((value == null) ? "(null)" : value.ToString());
}

[Conditional("DEBUG")]
public static void WriteLine(string format)
{
WriteLine("{0}", format);
}

[Conditional("DEBUG")]
public static void WriteLine(string format, params object[] values)
{
var formatted = String.Format(null, format, values);

Debug.WriteLine("{0:hh:mm:ss.fff} [{1:hh:mm:ss.fff}] {2}", DateTime.UtcNow, DateTime.UtcNow - lastLog, formatted);
lastLog = DateTime.UtcNow;
}
}

• This site is for requesting reviews of your code, not for publishing it. – svick Oct 22 '13 at 13:35

(value == null) ? string.Empty : value.ToString()


Consider whether something more descriptive would be suitable for null. Maybe something like "(null)".

public static void WriteLine(string format)


The name format is confusing here, because it's not actually format string, it's the value to write. So calling it value (like in the object overload) would make more sense. And maybe you don't need string overload at all.

DateTime.Now.ToUniversalTime()


You can write just DateTime.UtcNow. And you should do the same for lastLog too (assuming you keep it, see next item).

DateTime.Now - lastLog


I'm not sure what is this for. I don't think the time between two consecutive log entries is that interesting, it just clutters the log. And when it is interesting, you can compute the approximate time difference just by looking at it.

• Thanks for review! 1. What do you mean, "(null)" ? 3. Ok, seems simplier 4. Yep, deltatime between calls is looking quite nice in the second raw. For example, it shows that reading json with 30 items (like 5-7 fields per item) took 0.3 seconds. I'd never think that it can take that much amount of time, so i'd, probably, didnt even look there. Instead, having second raw as deltatime highlights this issues. Anyway, that's minor change everybody can fit themselves. – Vitalii Vasylenko Oct 22 '13 at 14:01
• @VitaliiVasylenko Ad 1. I meant that when the value is null, the logger would make it clear; something like value == null ? "(null)" : value.ToString(). – svick Oct 22 '13 at 14:06