DebugLog.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #define DEBUG
  2. namespace Caliburn.Micro.Core {
  3. using System;
  4. using System.Diagnostics;
  5. /// <summary>
  6. /// A simple logger thats logs everything to the debugger.
  7. /// </summary>
  8. public class DebugLog : ILog {
  9. private readonly string typeName;
  10. /// <summary>
  11. /// Initializes a new instance of the <see cref="DebugLog"/> class.
  12. /// </summary>
  13. /// <param name="type">The type.</param>
  14. public DebugLog(Type type) {
  15. typeName = type.FullName;
  16. }
  17. /// <summary>
  18. /// Logs the message as info.
  19. /// </summary>
  20. /// <param name="format">A formatted message.</param>
  21. /// <param name="args">Parameters to be injected into the formatted message.</param>
  22. public void Info(string format, params object[] args) {
  23. Debug.WriteLine("[{1}] INFO: {0}", string.Format(format, args), typeName);
  24. }
  25. /// <summary>
  26. /// Logs the message as a warning.
  27. /// </summary>
  28. /// <param name="format">A formatted message.</param>
  29. /// <param name="args">Parameters to be injected into the formatted message.</param>
  30. public void Warn(string format, params object[] args) {
  31. Debug.WriteLine("[{1}] WARN: {0}", string.Format(format, args), typeName);
  32. }
  33. /// <summary>
  34. /// Logs the exception.
  35. /// </summary>
  36. /// <param name="exception">The exception.</param>
  37. public void Error(Exception exception) {
  38. Debug.WriteLine("[{1}] ERROR: {0}", exception, typeName);
  39. }
  40. }
  41. }