Esempio n. 1
0
        internal IDisposable Trace(string helpFile)
        {
            TraceFrame frame = new TraceFrame(this, helpFile);

            this._traceFrames.Add(frame);
            return(frame);
        }
Esempio n. 2
0
        /// <summary>
        /// Helper method for getting the current stack trace
        /// </summary>
        /// <param name="declaringClassName"></param>
        /// <param name="maxFrames"></param>
        /// <param name="simpleMethodNames"></param>
        /// <returns></returns>
        public static List <TraceFrame> GetCurrentStackTrace(string declaringClassName, int maxFrames = 99, bool simpleMethodNames = false)
        {
            var frames = new List <TraceFrame>();

#if NETFULL
            try
            {
                //moves to the part of the trace where the declaring method starts then the other loop gets all the frames. This is to remove frames that happen within the logging library itself.
                var stackTrace       = new StackTrace(true);
                var stackTraceFrames = stackTrace.GetFrames();
                if (stackTraceFrames != null)
                {
                    int index1;

                    for (index1 = 0; index1 < stackTraceFrames.Length; ++index1)
                    {
                        var frame = stackTraceFrames[index1];

                        if (frame != null)
                        {
                            var method = frame.GetMethod();

                            if (method != null && method.DeclaringType != null &&
                                method.DeclaringType.FullName == declaringClassName)
                            {
                                break;
                            }
                        }
                    }

                    if (index1 < stackTraceFrames.Length)
                    {
                        for (int index2 = index1; index2 < stackTraceFrames.Length; ++index2)
                        {
                            var frame2 = stackTraceFrames[index2];
                            var f2     = new TraceFrame();
                            f2.CodeFileName = frame2.GetFileName();
                            f2.LineNum      = frame2.GetFileLineNumber();
                            f2.Method       = ErrorItem.GetMethodFullName(frame2.GetMethod(), simpleMethodNames);
                            frames.Add(f2);

                            if (frames.Count > maxFrames)
                            {
                                return(frames);
                            }
                        }
                    }
                }
            }
            catch
            {
                // ignored
            }
#endif
            return(frames);
        }
Esempio n. 3
0
        /// <summary>
        /// This is the api function used for adding errorRecords to TraceFrame's error
        /// pool.
        /// </summary>
        /// <param name="errorRecords"></param>
        internal void TraceErrors(Collection <ErrorRecord> errorRecords)
        {
            if (_traceFrames.Count == 0)
            {
                return;
            }

            TraceFrame traceFrame = _traceFrames[_traceFrames.Count - 1];

            traceFrame.TraceErrors(errorRecords);
        }
Esempio n. 4
0
        /// <summary>
        /// This is the api function used for adding errorRecords to TraceFrame's error
        /// pool.
        /// </summary>
        /// <param name="errorRecord"></param>
        internal void TraceError(ErrorRecord errorRecord)
        {
            if (_traceFrames.Count == 0)
            {
                return;
            }

            TraceFrame traceFrame = _traceFrames[_traceFrames.Count - 1];

            traceFrame.TraceError(errorRecord);
        }
Esempio n. 5
0
 internal void PopFrame(TraceFrame traceFrame)
 {
     if (this._traceFrames.Count > 0)
     {
         TraceFrame frame = (TraceFrame)this._traceFrames[this._traceFrames.Count - 1];
         if (frame == traceFrame)
         {
             this._traceFrames.RemoveAt(this._traceFrames.Count - 1);
         }
     }
 }
Esempio n. 6
0
 internal void PopFrame(TraceFrame traceFrame)
 {
     if (this._traceFrames.Count > 0)
     {
         TraceFrame frame = (TraceFrame) this._traceFrames[this._traceFrames.Count - 1];
         if (frame == traceFrame)
         {
             this._traceFrames.RemoveAt(this._traceFrames.Count - 1);
         }
     }
 }
Esempio n. 7
0
        internal void PopFrame(TraceFrame traceFrame)
        {
            if (_traceFrames.Count == 0)
            {
                return;
            }

            TraceFrame lastFrame = _traceFrames[_traceFrames.Count - 1];

            if (lastFrame == traceFrame)
            {
                _traceFrames.RemoveAt(_traceFrames.Count - 1);
            }
        }
Esempio n. 8
0
 internal IDisposable Trace(string helpFile)
 {
     TraceFrame frame = new TraceFrame(this, helpFile);
     this._traceFrames.Add(frame);
     return frame;
 }
Esempio n. 9
0
        internal void PopFrame(TraceFrame traceFrame)
        {
            if (_traceFrames.Count <= 0)
                return;

            TraceFrame lastFrame = (TraceFrame)_traceFrames[_traceFrames.Count - 1];

            if (lastFrame == traceFrame)
            {
                _traceFrames.RemoveAt(_traceFrames.Count - 1);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// This is the API to use for starting a help trace scope
        /// </summary>
        /// <param name="helpFile"></param>
        /// <returns></returns>
        internal IDisposable Trace(string helpFile)
        {
            TraceFrame traceFrame = new TraceFrame(this, helpFile);

            _traceFrames.Add(traceFrame);

            return traceFrame;
        }