x


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.

more ▼

asked Sep 16 '11 at 11:47 PM

Waz gravatar image

Waz
6.4k 22 33 70

(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

For some reason, using WWW to access the file rather than System.File.IO avoids the access violation. (thanks for the idea, @jahroy!)

more ▼

answered Sep 17 '11 at 12:33 AM

Waz gravatar image

Waz
6.4k 22 33 70

(comments are locked)
10|3000 characters needed characters left

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();
        }
more ▼

answered Mar 08 at 04:21 AM

levwsr gravatar image

levwsr
16

(comments are locked)
10|3000 characters needed characters left

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...

more ▼

answered Sep 17 '11 at 12:03 AM

jahroy gravatar image

jahroy
3.2k 14 18 41

Sorry, I specifically mean programmatically. I'll improve my title.

Sep 17 '11 at 12:07 AM Waz
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Sep 17 '11 at 12:24 AM

jahroy gravatar image

jahroy
3.2k 14 18 41

Copying requires reading the file, which is the thing that doesn't work.

Sep 17 '11 at 12:31 AM Waz
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1665
x67
x17
x2

asked: Sep 16 '11 at 11:47 PM

Seen: 880 times

Last Updated: Mar 08 at 04:21 AM