Log.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. namespace SharpCompress.Compressors.LZMA
  5. {
  6. internal static class Log
  7. {
  8. private static readonly Stack<string> INDENT = new Stack<string>();
  9. private static bool NEEDS_INDENT = true;
  10. static Log()
  11. {
  12. INDENT.Push("");
  13. }
  14. public static void PushIndent(string indent = " ")
  15. {
  16. INDENT.Push(INDENT.Peek() + indent);
  17. }
  18. public static void PopIndent()
  19. {
  20. if (INDENT.Count == 1)
  21. {
  22. throw new InvalidOperationException();
  23. }
  24. INDENT.Pop();
  25. }
  26. private static void EnsureIndent()
  27. {
  28. if (NEEDS_INDENT)
  29. {
  30. NEEDS_INDENT = false;
  31. #if !NO_FILE
  32. Debug.Write(INDENT.Peek());
  33. #endif
  34. }
  35. }
  36. public static void Write(object value)
  37. {
  38. EnsureIndent();
  39. #if !NO_FILE
  40. Debug.Write(value);
  41. #endif
  42. }
  43. public static void Write(string text)
  44. {
  45. EnsureIndent();
  46. #if !NO_FILE
  47. Debug.Write(text);
  48. #endif
  49. }
  50. public static void Write(string format, params object[] args)
  51. {
  52. EnsureIndent();
  53. #if !NO_FILE
  54. Debug.Write(string.Format(format, args));
  55. #endif
  56. }
  57. public static void WriteLine()
  58. {
  59. Debug.WriteLine("");
  60. NEEDS_INDENT = true;
  61. }
  62. public static void WriteLine(object value)
  63. {
  64. EnsureIndent();
  65. Debug.WriteLine(value);
  66. NEEDS_INDENT = true;
  67. }
  68. public static void WriteLine(string text)
  69. {
  70. EnsureIndent();
  71. Debug.WriteLine(text);
  72. NEEDS_INDENT = true;
  73. }
  74. public static void WriteLine(string format, params object[] args)
  75. {
  76. EnsureIndent();
  77. Debug.WriteLine(string.Format(format, args));
  78. NEEDS_INDENT = true;
  79. }
  80. }
  81. }