Reference
yusong:http://www.xuanyusong.com/archives/2477
Sandals: https://www.cnblogs.com/liangxiegame/p/Unity-you-xi-kuang-jia-da-jian-ba-jian-shao-jia-ba.html
According to the information on the Internet to integrate and change the whole
Using thread brushes
The generated files are in the Persistentdatapath directory
usingUnityengine;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Text;usingSystem.Threading; Public classoutlog:monobehaviour{Private ObjectMloglock =NULL; PrivateThread Mfilelogthread =NULL; Staticlist<string> mlines =Newlist<string>(); Staticlist<string> mwritetxt =Newlist<string>(); Private stringOutpath; /// <summary> ///You can also manually control this manual start/// </summary> voidStart () {Mloglock=New Object(); //Application.persistentdatapath Unity is the only path that can be read or written. Outpath = Application.persistentdatapath +"/outlog.txt"; //log saved before each startup client is deleted if(System.IO.File.Exists (Outpath)) {file.delete (Outpath); } //do a log listener here (old method, deprecated)//Application.registerlogcallback (Handlelog); //using thread brushesapplication.logmessagereceivedthreaded + =Handlelog; This. Mfilelogthread =NewThread (NewThreadStart (Writelog)); This. Mfilelogthread.start (); //an outputDebug.Log ("==============unity Client log log ========="); } /// <summary> ///thread Brushes/// </summary> voidWritelog () { while(true) { //Thread Lock Lock(mloglock) {if(Mwritetxt.count >0) { string[] temp =Mwritetxt.toarray (); foreach(stringTinchtemp) { using(StreamWriter writer =NewStreamWriter (Outpath,true, Encoding.UTF8)) {writer. WriteLine (t); } mwritetxt.remove (t); } } } } } /// <summary> ///use Update to brush (deprecated)/// </summary> voidUpdatenotuse () {//because the operation to write to the file must be done in the main thread, in the update, you write the file. if(Mwritetxt.count >0) { string[] temp =Mwritetxt.toarray (); foreach(stringTinchtemp) { using(StreamWriter writer =NewStreamWriter (Outpath,true, Encoding.UTF8)) {writer. WriteLine (t); } mwritetxt.remove (t); } } } Public Static stringGetHead () {return "["+ System.DateTime.Now.ToString ("yyyy-mm-dd HH:mm:ss FFF") +"] "; } voidHandlelog (stringLogstring,stringstackTrace, LogType type) {Mwritetxt.add (GetHead ()+logstring); if(type = = Logtype.error | | type = =logtype.exception) {//Log (logstring); //Log (stackTrace);Mwritetxt.add ("ERROR:"+stackTrace); } } //Here I save the wrong information for output on the phone screen (temporarily off) Static Public voidLog (params Object[] objs) { stringText =""; for(inti =0; I < Objs. Length; ++i) {if(i = =0) {text+=Objs[i]. ToString (); } Else{text+=", "+Objs[i]. ToString (); } } if(application.isplaying) {if(Mlines.count > -) {mlines.removeat (0); } mlines.add (text); } } voidOngui () {Gui.color=color.red; for(inti =0, IMAX = Mlines.count; I < IMAX; ++i) {Guilayout.label (mlines[i]); } }}
Unity collects log tools