Lino-IT:
Serverwartung
Bitte beachten
In dieser Zeit steht Lobster und die Datenbank nicht zur Verfügung
Added by Lino Ventura 7 months ago
Bitte beachten
In dieser Zeit steht Lobster und die Datenbank nicht zur Verfügung
Added by Michal Konieczny 8 months ago
1
2
3
Added by Michal Konieczny 8 months ago
1
2
Added by Рамил Сейфутдинов 9 months ago
Подвинул шкаф ясн. подвинулась проходка
Added by asd asd 9 months ago
Bravoooo
Added by Ralf Hesse 10 months ago
Grundlagen für eine Erweiterte Gewaltenteilung sollen in diesem Projekt erarbeitet werden.
Added by Kyle Storm 10 months ago
Body of the news stuff here
Added by Zane Zane 10 months ago
是的,你可以 单独开一个线程专门用于写日志文件,这样即使主线程(比如 Unity 游戏逻辑线程)崩溃了,只要进程还在运行、日志线程没崩溃,就尽可能地保留错误发生前的关键信息。这是一种更稳健的日志方案,适用于排查崩溃前的上下文。
Application.logMessageReceivedThreaded 可以在任意线程中接收到日志(包括崩溃前的线程)using UnityEngine;
using System.Collections.Concurrent;
using System.Threading;
using System.IO;
public class ThreadedLogger : MonoBehaviour
{
private ConcurrentQueue<string> logQueue = new ConcurrentQueue<string>();
private Thread logThread;
private bool isRunning = true;
private StreamWriter logWriter;
void Awake()
{
string fileName = $"Log_{System.DateTime.Now:yyyy-MM-dd_HH-mm-ss}.txt";
string filePath = Path.Combine(Application.persistentDataPath, fileName);
logWriter = new StreamWriter(filePath, true) { AutoFlush = true };
// 注册全局日志事件(主线程 + 子线程)
Application.logMessageReceivedThreaded += OnLogMessage;
// 启动日志线程
logThread = new Thread(LogWriterThread);
logThread.IsBackground = true;
logThread.Start();
}
void OnLogMessage(string condition, string stackTrace, LogType type)
{
string timestamp = System.DateTime.Now.ToString("HH:mm:ss.fff");
string logEntry = $"[{timestamp}] [{type}] {condition}";
if (type == LogType.Exception || type == LogType.Error)
{
logEntry += $"\n{stackTrace}";
}
logQueue.Enqueue(logEntry);
}
void LogWriterThread()
{
while (isRunning)
{
while (logQueue.TryDequeue(out string log))
{
logWriter.WriteLine(log);
}
Thread.Sleep(10); // 减少 CPU 占用
}
}
void OnDestroy()
{
isRunning = false;
logThread?.Join();
Application.logMessageReceivedThreaded -= OnLogMessage;
logWriter?.Close();
}
}
ConcurrentQueue 保证线程安全logThread 设置为后台线程(IsBackground = true),确保进程结束时不阻塞Player.log 更可靠,尤其适合临近崩溃的瞬间是否还需要我帮你集成这套日志系统到上传工单(Web)功能中?也可以加上崩溃前系统信息(SystemInfo)自动打包。
Added by Cacatua Fascinerosa 11 months ago
no hay ninguna descripción para agregar. No temas.
Added by Cacatua Fascinerosa 11 months ago
Después de tanto afanar, al fin los jueces se pusieron las pilas e hicieron lo que tenían que hacer.
Also available in: Atom