using XGame.Framework.Utils;
using LitJson;
using System;
using System.Collections.Generic;
namespace XGame.Framework.Logger
{
internal struct LogEventEntity
{
public string event_time;
///
/// 埋点类型
///
public string event_type;
///
/// 埋点ID
///
public string event_id;
///
/// 埋点信息
///
public Dictionary 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();
}
}
}