- Home /
Reading Editor.log in the Editor (programmatically)?
It seems that I cannot read Editor.log
programmatically, as it is locked:
var logFile = "C:/Users/Warwick/AppData/Local/Unity/Editor/Editor.log";
var all = System.IO.File.ReadAllText(logFile);
produces:
IOException: Sharing violation on path C:\Users\Warwick\AppData\Local\Unity\Editor\Editor.log
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options)
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share)
(wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
...
Is there any other way to access the log file?
Specifically I am trying to extract and process the Size information produced during build.
Answer by levwsr · Mar 08, 2013 at 04:21 AM
You need to open the file with file sharing...
FileMode fm = FileMode.Open; string contents = "";
FileStream fs = new FileStream("C:/Users/Bob/AppData/Local/Unity/Editor/Editor.log", fm, FileAccess.ReadWrite, FileShare.ReadWrite);
StreamReader sr = new StreamReader(fs);
if (fs != null && sr != null)
{
contents = sr.ReadToEnd();
}
Answer by jahroy · Sep 17, 2011 at 12:03 AM
I've heard you can use the WWW class to access files just about anywhere on the system if the URL starts with file:///
I've never tried it myself, but WWW is pretty easy to use.
I do have a vague memory of a post where using two or three slashes makes a difference.
This isn't the thread I'm thinking of, but it discusses using WWW to read files.
http://answers.unity3d.com/questions/159765/reading-a-local-file-from-webplayer-i-know-it-viol.html
I don't know if that will help you get around the fact that it's locked, though.
Is there no way to access asset size information without reading the file? I guess you're talking about the editor and it may not use the same optimized Assets.
I'll stop rambling now...
Sorry, I specifically mean programmatically. I'll improve my title.
Answer by jahroy · Sep 17, 2011 at 12:24 AM
You could probably write a PostprocessBuildPlayer script that copies the log file somewhere else.
You could copy it to your resources folder or your Assets folder and use it as a TextAsset.
Copying requires reading the file, which is the thing that doesn't work.