Access the log file in script
I'd like to access the log file in my script and send it by email when a user chooses such an option. Is there a possibility to do something like Debug.LogFile which would return a File object or something like that?
Answer by Landern · Nov 07, 2016 at 02:00 PM
Kinda, you would need to implement your own version of ILogHandler and ILogger, then finally change the associated logged from the default by setting Debug.logger. If everything goes alright and there isn't anything internal that checks for the project in release mode you can have the logger log however you want(hence the implementation of ILogHandler. The link provided for ILogHandler shows a log to FileStream, this would of course need options set on the platform to output the file(system file access and all that).
If the above doesn't work, you will either need to yoink an asset or design your own, there are plenty of simple logging solutions that exist open source, but just need to search for them through whatever search engine you use.
Well, I can simply take the file from %appdata%, but I thought there might an easier way. I don't really want to overwrite the whole logging system just to be able to easily send the log file over the email.
By easier I meant something dedicated to this simple task. :)
The current system is setup in such a way that you will need to implement your specific need one way or the other to gain what you want, but wouldn't be all that bad to implement yourself with reasonable conclusions that writing to the system can get expensive. If your game/program crashes then you may not have the information to push though email yet. If the issue is arising from things like reports your game is crashing, Unity has provided a class for that and the ability for you to pick up the information from the crash report(info here: https://docs.unity3d.com/ScriptReference/CrashReport.html). You can deter$$anonymous$$e if the game/program crashed and get the last report and send it.
Your answer
Follow this Question
Related Questions
Super noob question on Debug.Log or Log 1 Answer
How to log the GameObject from a Scriptable Object Event 0 Answers
Syntax 501 error, How to upload without error to FTP Server 1 Answer
Unity GerFile doesn't work on build 0 Answers
Can someone explain to me how FileUtil.CopyFileOrDirectory works ? 0 Answers