33 lines
909 B
C#
33 lines
909 B
C#
using System;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
public class CustomEditorLogger : MonoBehaviour
|
|
{
|
|
private string logFilePath;
|
|
|
|
private void OnEnable()
|
|
{
|
|
string text = DateTime.Now.ToString("dd-MM-yyyy HH mm ss");
|
|
string path = "editorlog-" + text + ".txt";
|
|
logFilePath = Path.Combine(Application.persistentDataPath, path);
|
|
Application.logMessageReceived += HandleLog;
|
|
File.WriteAllText(logFilePath, "Log session started at " + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + "\n");
|
|
}
|
|
|
|
private void HandleLog(string logString, string stackTrace, LogType type)
|
|
{
|
|
string text = DateTime.Now.ToString("HH:mm:ss") + " [" + type.ToString() + "] " + logString + "\n";
|
|
if (type == LogType.Exception || type == LogType.Error)
|
|
{
|
|
text = text + stackTrace + "\n";
|
|
}
|
|
File.AppendAllText(logFilePath, text);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
Application.logMessageReceived -= HandleLog;
|
|
}
|
|
}
|