Real-Time Logs
This feature is very useful, especially during testing phases if you have a built-in bug reporting system.
Your system could directly integrate the logs into the bug report. Don’t forget to ask for user consent through a checkbox, for example:
Report bug in one of my game
Windows
public void SendLog()
{
// get PlayerLog
var logPath = Path.Combine(Environment.GetEnvironmentVariable("AppData"), "..", "LocalLow", Application.companyName, Application.productName, "Player.log");
// get PlayerPrevLog
var preLogPath = Path.Combine(Environment.GetEnvironmentVariable("AppData"), "..", "LocalLow", Application.companyName, Application.productName, "Player-prev.log");
// read if file exists
if (File.Exists(logPath))
{
string logs = ReadShareFile(logPath);
}
}
// Logs are shared file we can read it with this function
private string ReadShareFile(string path)
{
using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (var textReader = new StreamReader(fileStream))
{
return textReader.ReadToEnd();
}
}
Linux
var pathLinux = CombinePaths("~/.config/unity3d", Application.companyName, Application.productName, "Player.log");
Mac
var pathMac = CombinePaths("~/Library/Logs", Application.companyName, Application.productName, "Player.log");
For Android and iOS, direct log collection is not possible. Native code needs to be used. However, as an alternative, you can subscribe to a log message event and then store them: Application.logMessageReceived
.
Or, you can create your own logging system, such as a Logger.
Original main illustration by Daniel Neiva Dan Neiva of Pixabay.