12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using XGame.Framework.Utils;
- using LitJson;
- using System;
- using System.Collections.Generic;
- namespace XGame.Framework.Logger
- {
- internal struct LogEventEntity
- {
- public string event_time;
- /// <summary>
- /// 埋点类型
- /// </summary>
- public string event_type;
- /// <summary>
- /// 埋点ID
- /// </summary>
- public string event_id;
- /// <summary>
- /// 埋点信息
- /// </summary>
- public Dictionary<string, string> info;
- public string ToConsoleString()
- {
- var sb = StringBuilderUtils.Acquire();
- foreach (var item in info)
- {
- sb.Append(item.Key);
- sb.Append(':');
- sb.Append(item.Value);
- sb.Append(' ');
- }
- var result = $"[{LogLevel.Event}][{event_type}][{event_id}]>>Info:[{sb}]";
- StringBuilderUtils.Release(sb);
- return result;
- }
- public string ToWriteString(JsonData jsondata) {
- jsondata.Clear();
- event_time = DateTime.UtcNow.AddHours(8).ToString("yyyy-MM-ddTHH:mm:ss.fffzzzz");
- jsondata["event_time"] = event_time;
- jsondata["event_type"] = event_type;
- jsondata["event_id"] = event_id;
- foreach (var current in info)
- {
- var key = $"extra.{event_type}.{event_id}.{current.Key}";
- jsondata[key] = current.Value;
- }
- return jsondata.ToJson();
- }
- }
- }
|