NetLog.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. using XGame.Framework.Utils;
  2. namespace XGame.Framework.Network
  3. {
  4. public static class NetLog
  5. {
  6. public static bool isVerbose = true;
  7. /// <summary>
  8. /// 比Debug更详细的log
  9. /// </summary>
  10. /// <param name="str"></param>
  11. [System.Diagnostics.Conditional(MacroDefine.DEBUG)]
  12. public static void LogVerbose(string str)
  13. {
  14. if (isVerbose)
  15. {
  16. Log.Debug($"<color=#00FF00>[Net] {str}</color>");
  17. }
  18. }
  19. [System.Diagnostics.Conditional(MacroDefine.DEBUG)]
  20. public static void LogHexString(string str_prefix, byte[] buffer, int offset, int length)
  21. {
  22. if (isVerbose)
  23. {
  24. var sb = StringBuilderUtils.Acquire();
  25. for (var i = offset; i < length + offset; i++)
  26. sb.Append(buffer[i].ToString("X2"));
  27. Log.Debug($"<color=#00FF00>[Net] {str_prefix} {sb}</color>");
  28. StringBuilderUtils.Release(sb);
  29. }
  30. }
  31. }
  32. }