/**
     	* 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;
			default:
				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.
			StringBuilder outputBuilder = new StringBuilder ();

			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);
			}
		}
Example #2
0
        private void WriteLine(object message, LogPriority priority)
        {
            var trace        = new StackTrace().GetFrame(2).GetMethod();
            var callerMethod = trace.DeclaringType.FullName;

            Log.WriteLine(priority, callerMethod, message.ToString());
            string logHeader = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss,fff} " +
                               $"{priority.ToString().ToUpper()}  {callerMethod}";
            string logMessage = message.ToString();

            lock (_lock)
            {
                using StreamWriter logWritter = new StreamWriter(CurrentLogPath, true, Encoding.UTF8);
                logWritter.WriteLine(logHeader);
                logWritter.WriteLine($" {logMessage}");
                logWritter.WriteLine();
            }
        }
Example #3
0
		public static void Log (string tag, LogPriority level, Exception t, params object[] messages)
		{
			if (Android.Util.Log.IsLoggable (tag, level)) {
				string message;
				if (t == null && messages != null && messages.Length == 1) {
					message = messages [0].ToString ();
				} else {
					var sb = new StringBuilder ();
					if (messages != null) {
						foreach (var m in messages) {
							sb.Append (m);
						}
					}
					if (t != null) {
						sb.Append ("\n").Append (Android.Util.Log.GetStackTraceString (Java.Lang.Throwable.FromException(t)));
					}
					message = sb.ToString ();
				}
				Android.Util.Log.WriteLine ((LogPriority)level, tag, message);
			}
		}
		/**
		* Prints data out to the console using Android's native log mechanism.
		*/
		public void WriteLine (LogPriority priority, string tag, string msg, Java.Lang.Throwable tr)
		{
			// There actually are log methods that don't take a msg parameter.  For now,
			// if that's the case, just convert null to the empty string and move on.
			String useMsg = msg ?? string.Empty;

			// If an exeption was provided, convert that exception to a usable string and attach
			// it to the end of the msg method.
			if (tr != null) {
				msg += "\n" + Android.Util.Log.GetStackTraceString (tr);
			}

			// This is functionally identical to Log.x(tag, useMsg);
			// For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
			Android.Util.Log.WriteLine (priority, tag, useMsg);

			// If this isn't the last node in the chain, move things along.
			if (NextNode != null) {
				NextNode.WriteLine (priority, tag, msg, tr);
			}
		}
Example #5
0
 public void WriteLine(LogPriority priority, string tag, string msg, Java.Lang.Throwable tr)
 {
     if (NextNode != null) {
         NextNode.WriteLine (LogPriority.Info, null, msg, null);
     }
 }
Example #6
0
 public static int WriteLine(LogPriority priority, string tag, string format, params object[] args)
 {
     return(WriteLine(priority, tag, string.Format(format, args)));
 }
Example #7
0
		/**
     	* Instructs the LogNode to print the log data provided. Other LogNodes can
     	* be chained to the end of the LogNode as desired.
    	*/
		public static void WriteLine (LogPriority priority, string tag, string msg)
		{
			WriteLine (priority, tag, msg, null);
		}
Example #8
0
		/**
    	* Instructs the LogNode to print the log data provided. Other LogNodes can
     	* be chained to the end of the LogNode as desired.
     	*/
		public static void WriteLine (LogPriority priority, string tag, string msg, Throwable tr)
		{
			if (mLogNode != null)
				mLogNode.WriteLine (priority, tag, msg, tr);
		}
Example #9
0
 public static int WriteLine(LogPriority priority, string tag, string format, params object[] args)
 {
     return WriteLine (priority, tag, string.Format (format, args));
 }