/// <summary> /// 线程函数,必须保证只有一个线程写日志 /// </summary> public void DoWork() { while (true) { if (CLDC_DataCore.Const.GlobalUnit.ApplicationIsOver) { break; } if (lstRunLog.Count > 0) { try { stLog _tagLog = lstRunLog[0]; if (_tagLog.LogPath != null) { System.IO.File.AppendAllText(_tagLog.LogPath, _tagLog.ToString()); lstRunLog.RemoveAt(0); } } catch (Exception EX) { string logPath = "/Log/Thread/LogThread-" + DateTime.Now.ToString("yyyy-MM-dd") + ".log"; WriteLog(logPath, this, "DoWork", EX.Message + "\r\n" + EX.StackTrace); } } System.Threading.Thread.Sleep(SleepTime); } }
public static void LogError(string format, params object[] arr) { // 调试android日志开启 //#if UNITY_IPHONE || UNITY_ANDROID //string log2 = string.Format(format, arr); //UnityEngine.Debug.Log(log2); //return; //#endif if (mLines == null) { return; } format = format.Replace("{}", "[zhongkuohao]"); string log = string.Format(format, arr); log = log.Replace("[zhongkuohao]", "{}"); //UnityEngine.Debug.Log(log); // 将信息输出到unity控制台 //UnityEngine.Debug.LogError(log); //return; //log = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss(fff)") + ": " + log; log = DateTime.Now.ToLocalTime().ToString("HH:mm:ss(fff)") + ": " + log; if (mLines.Count > maxCount) { mLines.RemoveAt(0); } #if CRASH_LOG UnityEngine.Debug.LogError("[UnityLog]" + log); #endif if (isBottom) { stLog stlog = new stLog(); stlog.logType = LOG_TYPE.LT_ERROR; stlog.logText = log; mLines.Add(stlog); scrollPosition.y += fontsize; //nowCount = mLines.Count; } //CreateInstance(); if (isShowConsole == false) { unSee++; unSeeError++; } }
private static void UnityLog(string format, params object[] arr) { if (mLines == null) { return; } //format = format.Replace("{}", "[zhongkuohao]"); string log = format; //string.Format(format, arr); //log = log.Replace("[zhongkuohao]", "{}"); //log = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss(fff)")+": " + log; log = DateTime.Now.ToLocalTime().ToString("HH:mm:ss(fff)") + ": " + log; if (mLines.Count > maxCount) { mLines.RemoveAt(0); } #if CRASH_LOG UnityEngine.Debug.Log("[UnityLog]" + log); #endif if (isBottom) { stLog stlog = new stLog(); stlog.logType = LOG_TYPE.LT_LOG; stlog.logText = log; mLines.Add(stlog); scrollPosition.y += fontsize; //nowCount = mLines.Count; } //CreateInstance(); if (isShowConsole == false) { unSee++; } }
private static void UnityException(Exception e) { if (mLines == null) { return; } string log = e.StackTrace; //log = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss(fff)") + ": " + log; log = DateTime.Now.ToLocalTime().ToString("HH:mm:ss(fff)") + ": " + log; if (mLines.Count > maxCount) { mLines.RemoveAt(0); } #if CRASH_LOG UnityEngine.Debug.LogException(e); #endif if (isBottom) { stLog stlog = new stLog(); stlog.logType = LOG_TYPE.LT_WARN; stlog.logText = log; mLines.Add(stlog); scrollPosition.y += fontsize; //nowCount = mLines.Count; } //CreateInstance(); if (isShowConsole == false) { unSee++; } }
/// <summary> /// 加入一条日志记录 /// </summary> /// <param name="LogFilePath">自定义保存路径</param> /// <param name="sender">发生者</param> /// <param name="FunName">过程名</param> /// <param name="LogMsg">要记录的内容</param> public void WriteLog(string LogFilePath, object sender, string FunName, string LogMsg) { string FilePath = String.Empty; stLog _tagLog = new stLog(); lock (objLock) { if (!Function.Common.IsEmpty(LogFilePath)) { FilePath = File.GetPhyPath(LogFilePath); } else { FilePath = m_strLogPath; } if (!System.IO.File.Exists(FilePath)) { System.IO.FileStream _FS = File.Create(FilePath); if (_FS != null) { _FS.Close(); } } System.Diagnostics.Debug.Assert(FilePath != null); if (sender == null) { sender = "null"; } _tagLog.Sender = sender.ToString() + "." + FunName; _tagLog.LogPath = FilePath; _tagLog.LogMsg = LogMsg; lstRunLog.Add(_tagLog); } }