我需要最简单的wp7记录器,没有网络报告或文件存储。只需向控制台报告简单。它应该能够使用字符串,对象和格式化字符串:
答案 0 :(得分:1)
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;
}
}