Files
UltimateFishing2020/Assets/Scripts/Assembly-CSharp/MasterCodeLogging.cs
2026-03-04 10:03:45 +08:00

59 lines
1.8 KiB
C#

using System;
using System.IO;
using UnityEngine;
public class MasterCodeLogging : MonoBehaviour
{
private static string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
private static string curFile = path + "\\_Ultimate Fishing Simulator 2";
private string filename = "";
private string output = "[" + DateTime.Now.Hour.ToString("00") + ":" + DateTime.Now.Minute.ToString("00") + ":" + DateTime.Now.Second.ToString("00") + "." + DateTime.Now.Millisecond.ToString("00") + "] > ";
public void OnEnable()
{
CheckFiles();
Application.logMessageReceived += Log;
}
public void OnDisable()
{
Application.logMessageReceived -= Log;
}
private void Awake()
{
UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
filename = curFile + $"\\logs_{DateTime.Now.Day}_{DateTime.Now.Month}_{DateTime.Now.Year}.mcode";
}
public static void CheckFiles()
{
if (!Directory.Exists(curFile))
{
Directory.CreateDirectory(path + "\\_Ultimate Fishing Simulator 2");
}
}
public void Log(string logString, string StackTrace, LogType type)
{
string text = logString.ToString();
TextWriter textWriter = new StreamWriter(filename, append: true);
if (!text.Contains("SetDestination"))
{
if (type == LogType.Error || type == LogType.Exception)
{
textWriter.Write(output + "==============================================================\n");
textWriter.Write(output + "============================ ERROR ===========================\n");
textWriter.Write(output + text + " at " + StackTrace + "\n");
textWriter.Write(output + "============================ ERROR ===========================\n");
textWriter.Write(output + "==============================================================\n");
textWriter.Write(output + "\n");
}
textWriter.Close();
}
}
}