예제 #1
0
        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)));
            }
        }
예제 #2
0
        /// <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)));
            }
        }