最简单的WP7记录器

时间:2013-10-22 07:37:20

标签: c# windows-phone-7 logging

我需要最简单的wp7记录器,没有网络报告或文件存储。只需向控制台报告简单。它应该能够使用字符串,对象和格式化字符串:

  • SimpleLogger.WriteLine( “JustLine”);
  • SimpleLogger.WriteLine(ObjectToBeCastedToString);
  • SimpleLogger.WriteLine(“价格为{0} {1}”,价格,货币);

1 个答案:

答案 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;
    }
}