如何在Unity中从控制台保存日志?

时间:2017-02-22 09:31:38

标签: c# unity3d

我让记录器从控制台登录到屏幕,如下所示: https://www.assetstore.unity3d.com/en/#!/content/49114

    void HandleLog(string message, string stackTrace, LogType type)
    {
        if (type == LogType.Assert && !LogErrors) return;
        if (type == LogType.Error && !LogErrors) return;
        if (type == LogType.Exception && !LogErrors) return;
        if (type == LogType.Log && !LogMessages) return;
        if (type == LogType.Warning && !LogWarnings) return;

        string[] lines = message.Split(new char[] { '\n' });

        foreach (string l in lines)
            queue.Enqueue(new LogMessage(l, type));

        if (type == LogType.Assert && !StackTraceErrors) return;
        if (type == LogType.Error && !StackTraceErrors) return;
        if (type == LogType.Exception && !StackTraceErrors) return;
        if (type == LogType.Log && !StackTraceMessages) return;
        if (type == LogType.Warning && !StackTraceWarnings) return;

        string[] trace = stackTrace.Split(new char[] { '\n' });

        foreach (string t in trace)
            if (t.Length != 0) queue.Enqueue(new LogMessage("  " + t,type));
    }

      void OnGUI()
    {
        ...
        foreach (LogMessage m in queue)
        {
            switch (m.Type)
            {
                case LogType.Warning:
                    styleText.normal.textColor = WarningColor;
                    break;

                case LogType.Log:
                    styleText.normal.textColor = MessageColor;
                    break;

                case LogType.Assert:
                case LogType.Exception:
                case LogType.Error:
                    styleText.normal.textColor = ErrorColor;
                    break;

                default:
                    styleText.normal.textColor = MessageColor;
                    break;
            }

            GUILayout.Label(m.Message, styleText);
        }

        GUILayout.EndArea();
    }

我想在点击保存按钮后将日志保存到数据库。 我应该在排队队列之后创建stringBuilder并附加文本,然后将stringBuilder写入属性或将xml发送到db? 什么是不仅保存消息文本而且还保存日志类型的解决方案?

0 个答案:

没有答案