LogEventEntity.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using XGame.Framework.Utils;
  2. using LitJson;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace XGame.Framework.Logger
  6. {
  7. internal struct LogEventEntity
  8. {
  9. public string event_time;
  10. /// <summary>
  11. /// 埋点类型
  12. /// </summary>
  13. public string event_type;
  14. /// <summary>
  15. /// 埋点ID
  16. /// </summary>
  17. public string event_id;
  18. /// <summary>
  19. /// 埋点信息
  20. /// </summary>
  21. public Dictionary<string, string> info;
  22. public string ToConsoleString()
  23. {
  24. var sb = StringBuilderUtils.Acquire();
  25. foreach (var item in info)
  26. {
  27. sb.Append(item.Key);
  28. sb.Append(':');
  29. sb.Append(item.Value);
  30. sb.Append(' ');
  31. }
  32. var result = $"[{LogLevel.Event}][{event_type}][{event_id}]>>Info:[{sb}]";
  33. StringBuilderUtils.Release(sb);
  34. return result;
  35. }
  36. public string ToWriteString(JsonData jsondata) {
  37. jsondata.Clear();
  38. event_time = DateTime.UtcNow.AddHours(8).ToString("yyyy-MM-ddTHH:mm:ss.fffzzzz");
  39. jsondata["event_time"] = event_time;
  40. jsondata["event_type"] = event_type;
  41. jsondata["event_id"] = event_id;
  42. foreach (var current in info)
  43. {
  44. var key = $"extra.{event_type}.{event_id}.{current.Key}";
  45. jsondata[key] = current.Value;
  46. }
  47. return jsondata.ToJson();
  48. }
  49. }
  50. }