DebugHelper.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Diagnostics;
  2. using System.Globalization;
  3. namespace PicView.Core.DebugTools;
  4. /// <summary>
  5. /// Provides helper methods for logging debug information during development.
  6. /// </summary>
  7. public static class DebugHelper
  8. {
  9. /// <summary>
  10. /// Logs detailed debug information for an exception, including the class name, method name, message, and stack trace.
  11. /// This method is intended to be used for development and debugging purposes only.
  12. /// </summary>
  13. /// <param name="className">
  14. /// The name of the class where the exception occurred. Typically passed using
  15. /// <c>nameof(ClassName)</c>.
  16. /// </param>
  17. /// <param name="methodName">
  18. /// The name of the method where the exception occurred. Typically passed using
  19. /// <c>nameof(MethodName)</c>.
  20. /// </param>
  21. /// <param name="exception">The exception that was thrown.</param>
  22. /// <example>
  23. /// <code>
  24. /// catch (Exception ex)
  25. /// {
  26. /// DebugHelper.LogDebug(nameof(MyClass), nameof(MyMethod), ex);
  27. /// }
  28. /// </code>
  29. /// </example>
  30. public static void LogDebug(string className, string methodName, Exception exception)
  31. {
  32. Debug.WriteLine(
  33. $"\n[{DateTime.Now.ToString("T", CultureInfo.CurrentCulture)}] {className}.{methodName} exception: {exception.Message}");
  34. Debug.WriteLine(exception.StackTrace + Environment.NewLine);
  35. }
  36. public static void LogDebug(string appleScriptManagerName, string executeAppleScriptAsyncName, string exceptionMessage)
  37. {
  38. Debug.WriteLine(
  39. $"\n[{DateTime.Now.ToString("T", CultureInfo.CurrentCulture)}] {appleScriptManagerName}.{executeAppleScriptAsyncName} exception: {exceptionMessage}");
  40. }
  41. }