示例#1
0
    /// <summary>
    /// 清空txt文本日志内容
    /// </summary>
    public void ClearLog(MyLogType logtype)
    {
        InitLog(logtype);
        StreamWriter sw = new StreamWriter(fileName);

        sw.WriteLine("");
        sw.Close();
    }
示例#2
0
 private void InitLog(MyLogType logType)
 {
     m_logType = logType;
     fileName  = Application.dataPath + "/" + m_logType.ToString() + ".txt";
     if (!m_builderLogDic.ContainsKey(logType))
     {
         m_builderLogDic.Add(logType, new StringBuilder());
     }
     m_builderLog = m_builderLogDic[logType];
 }
示例#3
0
    /// <summary>
    /// 将记录在内存中的日志保存到txt文本中
    /// </summary>
    public void SaveTxt(MyLogType logtype)
    {
        InitLog(logtype);
        FileStream   filewriter = new FileStream(@fileName, FileMode.Append, FileAccess.Write);
        StreamWriter sw         = new StreamWriter(filewriter);

        sw.Write(m_builderLog.ToString());
        m_builderLog.Remove(0, m_builderLog.Length);
        sw.Close();
        filewriter.Close();
    }
示例#4
0
    /// <summary>
    /// 写日志
    /// </summary>
    /// <param name="smg"></param>
    public void WriteLog(MyLogType logtype, params string[] smg)
    {
        InitLog(logtype);
        string context = "";

        for (int i = 0; i < smg.Length; i++)
        {
            context += "," + smg[i];
        }
        m_builderLog.AppendLine(System.DateTime.Now.ToString() + ":" + System.DateTime.Now.ToString("fff") + context);
    }
示例#5
0
 public static MyLog SetLog(MyLogType type = MyLogType.LT_Normal)
 {
     if (instance == null)
     {
         GameObject log = new GameObject();
         log.name = "MyLog";
         MyLog ml = log.AddComponent <MyLog>();
         ml.mLogType = type;
         DontDestroyOnLoad(log);
         return(ml);
     }
     else
     {
         instance.mLogType = type;
     }
     return(instance);
 }
示例#6
0
        private void _OnDebugLogCallbackHandler(string name, string stack, LogType type)
        {
            LogInfo logInfo = new LogInfo()
            {
                logName = name, logType = type, logStack = stack
            };

            AllLog.Add(logInfo);
            if (type == LogType.Warning)
            {
                WarningLog.Add(logInfo);
            }
            else if (type == LogType.Error || type == LogType.Exception)
            {
                ErrorLog.Add(logInfo);
                if (mLogType == MyLogType.LT_Hide)
                {
                    mLogType    = MyLogType.LT_Normal;
                    mIsScale    = false;
                    mDetailInfo = logInfo;
                }

                //错误日志记录
                if (mLogVersion == null)
                {
                    mLogVersion = new LogVersion();
                    mLogVersion.ReadFile();
                    mLogVersion.version++;
                    mLogVersion.SaveFile();

                    mLogFile = new LogFile();
                    mLogFile.ReadFile(_GetLogPath(mLogVersion.version));
                    mLogFile.version = mLogVersion.version;
                    mLogFile.firstError.Clear();
                    mLogFile.time    = System.DateTime.Now.ToString("MM月dd日-HH:mm:ss");
                    mLogFile.mAllLog = null;
                }

                if (mLogFile.firstError.Count < 10)
                {
                    mLogFile.firstError.Add(logInfo);
                    mLogFile.mAllLog = AllLog;
                    mLogFile.SaveFile();
                }
            }
        }
示例#7
0
 /// <summary>
 /// 写日志 到内存中
 /// </summary>
 /// <param name="msg">写入的内容</param>
 public void WriteLog(MyLogType logtype, string msg)
 {
     InitLog(logtype);
     m_builderLog.AppendLine(System.DateTime.Now.ToString() + ":" + System.DateTime.Now.ToString("fff") + " debug: " + msg);
 }