System.Exception.GetBaseException C# (CSharp) Method

GetBaseException() public method

public GetBaseException ( ) : Exception
return Exception
        public virtual Exception GetBaseException() 
        {
            Exception inner = InnerException;
            Exception back = this;
            
            while (inner != null) {
                back = inner;
                inner = inner.InnerException;
            }
            
            return back;
        }
        

Usage Example

Example #1
0
        public static void log(string level, string comp, string msg, Exception e)
        {
            if (comp == null) comp = "";
            if (msg == null) msg = "";

            var nowms = DateTimeMs.NowMs;
            var ts = nowms.ToShortDateString().PadLeft(10) + " " + nowms.ToLongTimeString().PadLeft(8) + "." + nowms.Millisecond.ToString().PadLeft(3, '0');

            msg = "["+level+"] "+ ts + "["+comp+"]  " + msg;
            if (e != null)
            {
            msg +=  "\n" + e.GetType().ToString() + ": " + e.Message +"\n"+ e.StackTrace;
            }
            if (e != null && e.GetBaseException() != null && e.GetBaseException() != e)
            {
            e = e.GetBaseException();
            msg +=  "BaseException:\n" + e.GetType().ToString() + ": " + e.Message +"\n"+ e.StackTrace;
            }
            try{
            System.Console.WriteLine(msg);
            #if __ANDROID__
            Android.Util.Log.Error("", msg);
            #endif
            if (fs != null)
            {
                fs.Write(msg+"\n");
                fs.Flush();
            }
            }catch(Exception){}
        }
All Usage Examples Of System.Exception::GetBaseException