- Home /
Don't overwrite output_log.txt between runs
I'm looking for a way to keep the information in the output_log.txt file between runs of the application. As far as I can tell, Unity clears the file every time the application is started. This is what I'm trying to prevent.
Right now I have a coroutine that copies the output_log.txt file to a folder every couple of seconds. The issue with this solution is that if a crash happens, the most important lines in outpot_log.txt from just before the application crashed probably won't be copied. So I'm looking for a solution or an improvement to the solution I already have.
Any help would be appreciated!
Why do you copy the file every couple of seconds ins$$anonymous$$d of at start ?
@Hellium that's what I'm doing, I have a coroutine that copies the file every couple of seconds, not just at the start
$$anonymous$$y question is "why" you do this ? Copying the file when the game starts should be enough.
He's trying to catch crashes. It wouldn't really be a crash if it was calling OnApplicationQuit.
Answer by sarahnorthway · Jul 12, 2017 at 08:16 PM
In the advent of a crash, Unity makes a copy of output_log.txt, along with crash.dmp and error.log, and stores them in a subdirectory of GAMENAME_Data named the datetime of the crash.
I also often want play data from previous sessions that don't cause crashes. I considered using a Debug.Log wrapper that keeps its own independent log file, but it can't catch all internal Unity or DLL exceptions. Your method of duplicating output_log.txt regularly may be the best bet. Make sure you call it one last time during OnApplicationQuit, which should always run when the app quits correctly.
Unity has a log-event to which you can subscribe. It should be called for any log including internal errors. Application.log$$anonymous$$essageReceived The callback receives the actual message, a stacktrace as string as well as the log type
Your answer
![](https://koobas.hobune.stream/wayback/20220612114053im_/https://answers.unity.com/themes/thub/images/avi.jpg)