feat:1、添加项目
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using SGModule.NetKit;
|
||||
using BallKingdomCrush;
|
||||
using UnityEngine;
|
||||
|
||||
public class ErrorLogger : MonoBehaviour {
|
||||
// 用于存储报错信息的列表
|
||||
private readonly List<string> errorLogs = new();
|
||||
|
||||
private void OnEnable() {
|
||||
// 注册事件处理函数
|
||||
Application.logMessageReceived += HandleLog;
|
||||
}
|
||||
|
||||
private void OnDisable() {
|
||||
// 注销事件处理函数
|
||||
Application.logMessageReceived -= HandleLog;
|
||||
}
|
||||
|
||||
// 事件处理函数
|
||||
private void HandleLog(string logString, string stackTrace, LogType type) {
|
||||
// 只处理错误和异常类型的日志
|
||||
if (type == LogType.Error || type == LogType.Exception) {
|
||||
// 将报错信息和堆栈跟踪添加到列表中
|
||||
errorLogs.Add(logString);
|
||||
errorLogs.Add(stackTrace);
|
||||
|
||||
// 这里可以添加代码将报错信息发送给服务器
|
||||
SendErrorToServer(logString, stackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
// 如何将报错信息发送给服务器
|
||||
private void SendErrorToServer(string error, string stackTrace) {
|
||||
// Debug.Log($"SendErrorToServer-----------error\n{error}");
|
||||
// Debug.Log($"SendErrorToServer-----------stackTrace\n{stackTrace}");
|
||||
// 这里填写将报错信息发送到服务器的代码
|
||||
ErrorLogKit.Send("error", error, stackTrace,SuperApplication.Instance.attribution);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user