/// <summary> /// Log the specified logLevel, message, exception and tag. /// </summary> /// <param name="logLevel">Log level.</param> /// <param name="message">Message.</param> /// <param name="exception">Exception.</param> /// <param name="tag">Tag.</param> public void Log(LogLevel logLevel, string message, System.Exception exception, string tag = null) { if (exception != null) { message += string.Format(": {0}", exception.GetStackTrace()); } message = (string.IsNullOrEmpty(tag)) ? message : $"[{tag}] {message}"; switch (logLevel) { case LogLevel.Verbose: case LogLevel.Debug: case LogLevel.Info: case LogLevel.Warn: Console.WriteLine($"{LOG_TAG} {logLevel.ToString()} {message}"); break; case LogLevel.Error: Console.WriteLine($"{LOG_TAG} {logLevel.ToString()} {message}"); try { Crashes.TrackError(exception, null); // TODO: Other properties } catch (System.Exception ex) { Console.WriteLine($"{LOG_TAG} Error while reporting back to App Center - { ex.Message}"); // TODO: What to do? } break; } }
/// <summary> /// Log the specified logLevel, message, exception and tag. /// </summary> /// <param name="logLevel">Log level.</param> /// <param name="message">Message.</param> /// <param name="exception">Exception.</param> /// <param name="tag">Tag.</param> public void Log(LogLevel logLevel, string message, System.Exception exception, string tag = null) { if (exception != null) { message += string.Format(": {0}", exception.GetStackTrace()); } message = (string.IsNullOrEmpty(tag)) ? message : $"[{tag}] {message}"; switch (logLevel) { case LogLevel.Verbose: Android.Util.Log.Verbose(LOG_TAG, message); break; case LogLevel.Debug: Android.Util.Log.Debug(LOG_TAG, message); break; case LogLevel.Info: Android.Util.Log.Info(LOG_TAG, message); break; case LogLevel.Warn: Android.Util.Log.Warn(LOG_TAG, message); break; case LogLevel.Error: Android.Util.Log.Error(LOG_TAG, message); try { Crashes.TrackError(exception, null); // TODO: Other properties } catch (System.Exception ex) { Android.Util.Log.Error(LOG_TAG, $"Error while reporting back to App Center - {ex.Message}"); // TODO: What to do? } break; } }
public virtual string ReadCurrentFunctionJavaName() { Exception t = new Exception(); // remove prefix and suffix of method name return t.GetStackTrace()[8].GetMethodName().ReplaceFirst("_[^_]*_(.*)_[^_]*", "$1"); }
/** Return first non ErrorManager code location for generating messages */ private static StackFrame GetLastNonErrorManagerCodeLocation( Exception e ) { StackFrame[] stack = e.GetStackTrace(); int i = 0; for ( ; i < stack.Length; i++ ) { StackFrame t = stack[i]; if ( t.ToString().IndexOf( "ErrorManager" ) < 0 ) { break; } } StackFrame location = stack[i]; return location; }