我需要最简单的 wp7 记录器,不需要网络报告或文件存储。只是简单的向控制台报告。它应该能够处理字符串、对象和格式化字符串:
- SimpleLogger.WriteLine("JustLine");
- SimpleLogger.WriteLine(ObjectToBeCastedToString);
- SimpleLogger.WriteLine("价格为 {0} {1}", price, currency);
我需要最简单的 wp7 记录器,不需要网络报告或文件存储。只是简单的向控制台报告。它应该能够处理字符串、对象和格式化字符串:
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;
}
}