示例#1
0
    ///<summary>
    /// Display a message in the CLI.
    ///</summary>
    ///<param name="_line">The text to display</param>
    ///<param name="_color">The color of the text. Default is white</param>
    public void AppendLogLine(string _line, bool _writeInCli, eLogtype _type = eLogtype.info)
    {
        if (!writeLogs)
        {
            return;
        }

        // Legacy build-in CLI
        string color = "";

        if (_type == eLogtype.info)
        {
            color = "white";
        }
        else if (_type == eLogtype.success)
        {
            color = "green";
        }
        else if (_type == eLogtype.warning)
        {
            color = "yellow";
        }
        else if (_type == eLogtype.error)
        {
            color = "red";
        }
        consoleController.AppendLogLine(_line, color);

        // Remote CLI
        if (_writeInCli)
        {
            try
            {
                server.Send(_line);
            }
            catch (System.Exception e)
            {
                Debug.LogError(e.Message);
            }
        }

        WriteLogFile(_line, _type);
        switch (_type)
        {
        case eLogtype.warning:
            Debug.LogWarning(_line);
            break;

        case eLogtype.error:
            Debug.LogError(_line);
            break;

        default:
            Debug.Log(_line);
            break;
        }
    }
示例#2
0
    ///
    private void WriteLogFile(string _str, eLogtype _type)
    {
        string dateTime = System.DateTime.Now.ToString();
        string type     = "";

        switch (_type)
        {
        case eLogtype.info:
            type = "INFO";
            break;

        case eLogtype.success:
            type = "SUCCESS";
            break;

        case eLogtype.warning:
            type = "WARNING";
            break;

        case eLogtype.error:
            type = "ERROR";
            break;
        }
        if (_str[_str.Length - 1] != '\n')
        {
            _str += "\n";
        }

        string     fileName = $"{configLoader.GetCacheDir()}/log.txt";
        FileStream fs       = null;

        try
        {
            fs = new FileStream(fileName, FileMode.Append);
            using (StreamWriter writer = new StreamWriter(fs))
            {
                writer.Write($"{dateTime} | {type}: {_str}");
            }
        }
        catch (System.Exception _e)
        {
            Debug.LogError(_e.Message);
        }
        finally
        {
            if (fs != null)
            {
                fs.Dispose();
            }
        }
    }