private static ErrReport GetErrReport(int code, string msg) { try { ErrReport err; List <string> stackFrames; //------------------------------------------------------ // TODO - See the Standard version which uses the interface IStackTools to process the stack frame //------------------------------------------------------ err = new ErrReport(code, StackFrameTools.FirstNonWrappedMethod2(typeof(WrapErr)), msg); stackFrames = StackFrameTools.FirstNonWrappedTraceStack(typeof(WrapErr), 2); //stackFrames = StackFrameTools.FirstNonWrappedTraceStack(typeof(WrapErr), new StackTrace(0,true)); StringBuilder sb = new StringBuilder(100); stackFrames.ForEach((item) => sb.AppendLine(item)); err.StackTrace = sb.ToString(); return(WrapErr.LogErr(err)); } catch (Exception ex) { Debug.WriteLine("{0} on call to WrapErr.GetErrReport:{1} - {2}", ex.GetType().Name, ex.Message, ex.StackTrace); return(WrapErr.LogErr(new ErrReport(code, "UnknownClass", "UnknownMethod", msg))); } }
/// <summary> /// Helper to create an error report object with the class and method names of calling method that /// had an exeption occur. Names are found by relection /// </summary> /// <param name="code">Unique error code</param> /// <param name="msg">Error message</param> /// <param name="e">Exception of origine</param> /// <returns>And error report object</returns> private static ErrReport GetErrReport(int code, string msg, Exception e) { try { //------------------------------------------------------ // TODO - See the Standard version which uses the interface IStackTools to process the stack frame //------------------------------------------------------ if (msg == REPLACE_WITH_EXCEPTION_MSG) { msg = e.Message; } // Always needs to be called directly from one of the wrap objects to get the right number of the stack frame // This will give us the class and method names in which the wrap method is used return(WrapErr.LogErr(new ErrReport(code, StackFrameTools.FirstNonWrappedMethod2(typeof(WrapErr)), msg, e))); } catch (Exception ex) { Debug.WriteLine("{0} on call to WrapErr.GetErrReport:{1} - {2}", ex.GetType().Name, ex.Message, ex.StackTrace); return(WrapErr.LogErr(new ErrReport(code, "UnknownClass", "UnknownMethod", msg, e))); } }
/// <summary>Used when catching an exception thrown by a check function so that the stack from throw can be logged</summary> /// <param name="chkException">The check exception object. Not written when check throws</param> /// <returns>The err report</returns> /// <remarks> /// The information such as class and method of origine are preserved from the check but the stack from the base class /// exception that was thrown on the Chkxxx method is what is processed for log. /// </remarks> private static ErrReport GetErrReport(ErrReportExceptionFromChk exp) { return(WrapErr.LogErr(new ErrReport(exp.Report.Code, exp.Report.AtClass, exp.Report.AtMethod, exp.Report.Msg, exp))); }