- Home /
Question by
Xpoint · Aug 06, 2017 at 09:20 AM ·
fileconsoleloggingwrite data
Console.WriteLine Redirect to file
Hi, I am trying to redirect the logs in unity to be written into a file in order to run the game on android and have the logs readable from my android devices. I am trying to use this in order to get the targeted result. This is my code
public static FileStream createFile(string filePath)
{
string path = Application.persistentDataPath + @"\" + filePath;
FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate);
return fileStream;
}
public static void setUpLogger()
{
try{
StreamWriter streamWriter = new StreamWriter (createFile (logFileName));
Console.SetOut (streamWriter);
}
catch(Exception ex) {
print ("Error while setting up logger; " + ex);
}
}
The file is created but when I call Console.log the string I pass is not written to the file And the file is still empty.
Thanks
Comment