Hello
I have tried a couple solutions to getting logging to work in a build but for some reason it’s not working. The latest thing I’ve tried was this script I found online. The code works just fine in the editor. If I press play I can see the logs and it saves it to a file
using UnityEngine;
public class X_LogReporter : MonoBehaviour
{
string myLog = "*begin log";
string filename = "";
bool doShow = true;
int kChars = 700;
void OnEnable() { Application.logMessageReceived += Log; }
void OnDisable() { Application.logMessageReceived -= Log; }
void Update() {
if (Input.GetKeyDown(KeyCode.Space))
{
doShow = !doShow;
}
}
public void Log(string logString, string stackTrace, LogType type)
{
// for onscreen...
myLog = myLog + "\n" + logString;
if (myLog.Length > kChars) { myLog = myLog.Substring(myLog.Length - kChars); }
// for the file ...
if (filename == "")
{
string d = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Desktop) + "/GRRBLS_LOG";
System.IO.Directory.CreateDirectory(d);
string r = Random.Range(1000, 9999).ToString();
filename = d + "/log-" + r + ".txt";
}
try { System.IO.File.AppendAllText(filename, logString + "\n"); }
catch { }
}
void OnGUI()
{
if (!doShow) { return; }
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity,
new Vector3(Screen.width / 1200.0f, Screen.height / 800.0f, 1.0f));
GUI.TextArea(new Rect(10, 10, 540, 370), myLog);
}
}
In the editor the log shows up fine:
When I build and run the game, it stops working
Any suggestions on what I might be missing or where to look. All my research indicates Debug.Log should work in builds and I can’t see what I might have wrong.