Ejemplo n.º 1
0
        /**
         * Formats the log data and prints it out to the LogView.
         */
        public void WriteLine(LogPriority priority, string tag, string msg, Java.Lang.Throwable tr)
        {
            string priorityStr = null;

            // For the purposes of this View, we want to print the priority as readable text.
            switch (priority)
            {
            case LogPriority.Verbose:
                priorityStr = "VERBOSE";
                break;

            case LogPriority.Debug:
                priorityStr = "DEBUG";
                break;

            case LogPriority.Info:
                priorityStr = "INFO";
                break;

            case LogPriority.Warn:
                priorityStr = "WARN";
                break;

            case LogPriority.Error:
                priorityStr = "ERROR";
                break;

            case LogPriority.Assert:
                priorityStr = "ASSERT";
                break;
            }

            // Handily, the Log class has a facility for converting a stack trace into a usable string.
            string exceptionStr = null;

            if (tr != null)
            {
                exceptionStr = Android.Util.Log.GetStackTraceString(tr);
            }

            // Take the priority, tag, message, and exception, and concatenate as necessary
            // into one usable line of text.
            var outputBuilder = new StringBuilder();

            const string delimiter = "\t";

            AppendIfNotNull(outputBuilder, priorityStr, delimiter);
            AppendIfNotNull(outputBuilder, tag, delimiter);
            AppendIfNotNull(outputBuilder, msg, delimiter);
            AppendIfNotNull(outputBuilder, exceptionStr, delimiter);

            // In case this was originally called from an AsyncTask or some other off-UI thread,
            // make sure the update occurs within the UI thread.

            ((Activity)Context).RunOnUiThread(new Action(delegate {
                AppendToLog(outputBuilder.ToString());
            }));

            if (NextNode != null)
            {
                NextNode.WriteLine(priority, tag, msg, tr);
            }
        }