How do I find the player log file from code?

I want to write a script to upload logfiles with a bugreport. How do I find the logfile? (For production, so no editor logs.)

The documentation gives these paths:

  • macOS ~/Library/Logs/Unity/Player.log
  • Linux ~/.config/unity3d/CompanyName/ProductName/Player.log
  • Windows Unity 5.6 EXECNAME_Data\output_log.txt
  • Windows Unity 2017+ C:\Users\username\AppData\LocalLow\CompanyName\ProductName\output_log.txt

How do I translate these paths into code?

CommandLineArguments docs has an entry for a -logFile option:

Specify where the Editor or Windows/Linux/OSX standalone log file are written.

If that’s used, is there a way to get a path to the log file?

It’s now pretty easy to write a log file anywhere you want:

Just use:

void OnEnable() { Application.logMessageReceived += Log;  }
void OnDisable() { Application.logMessageReceived -= Log; }

Full example:

For code examples, I assume you have CombinePaths.



Straightforward: just use that path.



CompanyName/ProductName are values from Edit > Settings > Player. They’re exposed in code:

var log_path = CombinePaths("~/.config/unity3d", Application.companyName, Application.productName, "Player.log");



Unity 2017+ C:\Users\username\AppData\LocalLow\CompanyName\ProductName\output_log.txt

On recent versions of Unity, this should work for Windows:

var log_path = CombinePaths(Environment.GetEnvironmentVariable("AppData"), "..", "LocalLow", Application.companyName, Application.productName, "output_log.txt");


Unity 5.6 EXECNAME_Data\output_log.txt

But for 5.6, docs say:

On Windows, EXECNAME_Data is a folder next to the executable with your game.

According to how do i get the application path, you can base it off of dataPath:

// Unity strips some characters from productName to make the exe name. I've
// also seen it convert to lower case.
var exe_basename = Application.productName.Replace(" ", "");
var log_path = CombinePaths(Application.dataPath, "..", exe_basename +"_Data", "output_log.txt");



For -logFile, I think you have to parse the System.Environment.GetCommandLineArgs.

In summarising all the options available:

  • Use the first answer if you need the whole log the unity player has generated (noting that unity can backup/rename the file after each run)
  • Use the second answer if you want to capture events once the app has started, this is also useful if you want to filter the logs and get specific data.
  • If you need a more advanced method and want to capture just your own data with a little flair, then use a Logger (Unity - Scripting API: Logger)