Unofficial CardLife revival project, pronounced like "celery"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.1KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using System.Diagnostics;
  5. namespace CLre_server.API.Utility
  6. {
  7. /// <summary>
  8. /// Utility class to access Cardlife's built-in logging capabilities.
  9. /// The log is saved to outputLog#.Log
  10. /// </summary>
  11. public static class Logging
  12. {
  13. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  14. public static void Log(string msg)
  15. {
  16. Svelto.Console.Log(msg);
  17. }
  18. /// <summary>
  19. /// Write a regular message to Cardlife's log
  20. /// </summary>
  21. /// <param name="obj">The object to log</param>
  22. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  23. public static void Log(object obj)
  24. {
  25. Svelto.Console.Log(obj.ToString());
  26. }
  27. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  28. public static void LogError(string msg, Dictionary<string, string> extraData = null)
  29. {
  30. Svelto.Console.LogError(msg, extraData);
  31. }
  32. /// <summary>
  33. /// Write an error message to Cardlife's log
  34. /// </summary>
  35. /// <param name="obj">The object to log</param>
  36. /// <param name="extraData">The extra data to pass to the ILogger</param>
  37. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  38. public static void LogError(object obj, Dictionary<string, string> extraData = null)
  39. {
  40. Svelto.Console.LogError(obj.ToString(), extraData);
  41. }
  42. /// <summary>
  43. /// Write an exception to Cardlife's log and to the screen and exit game
  44. /// </summary>
  45. /// <param name="e">The exception to log</param>
  46. /// <param name="extraData">The extra data to pass to the ILogger.
  47. /// This is automatically populated with "OuterException#" and "OuterStacktrace#" entries</param>
  48. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  49. public static void LogException(Exception e, string msg = null, Dictionary<string, string> extraData = null)
  50. {
  51. Svelto.Console.LogException(msg, e, extraData);
  52. }
  53. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  54. public static void LogWarning(string msg)
  55. {
  56. Svelto.Console.LogWarning(msg);
  57. }
  58. /// <summary>
  59. /// Write a warning message to Cardlife's log
  60. /// </summary>
  61. /// <param name="obj">The object to log</param>
  62. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  63. public static void LogWarning(object obj)
  64. {
  65. Svelto.Console.LogWarning(obj.ToString());
  66. }
  67. // descriptive logging
  68. /// <summary>
  69. /// Write a descriptive message to Cardlife's log including the calling method's name
  70. /// </summary>
  71. /// <param name="obj">The object to log</param>
  72. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  73. public static void MetaLog(object obj)
  74. {
  75. var method = (new StackTrace()).GetFrame(1).GetMethod();
  76. Log($"[{method.DeclaringType.FullName}.{method.Name}] {obj.ToString()}");
  77. }
  78. }
  79. }