Ejemplo n.º 1
0
        internal TraceFrame(string message, MethodBase caller, GenerateTraceFrameEventMessages frameEventMessagesGenerateMode)
        {
            Message = message;
            Caller  = caller;
            FrameEventMessagesGenerateMode = frameEventMessagesGenerateMode;

            if (RootTraceFrame == null)
            {
                RootTraceFrame = this;
            }
            else
            {
                TraceFrame lastTraceFrame = RootTraceFrame;

                while (lastTraceFrame._nextTraceFrame != null)
                {
                    lastTraceFrame = lastTraceFrame._nextTraceFrame;
                }

                lastTraceFrame._nextTraceFrame = this;
            }

            if (FrameEventMessagesGenerateMode == GenerateTraceFrameEventMessages.GenerateAll)
            {
                TraceHelper.TraceFrameEvent(TraceFrameEventType.Started, this);
            }
        }
Ejemplo n.º 2
0
        private void Dispose(bool calledByFinalizer)
        {
            if (_isUnderDisposal == false)
            {
                _isUnderDisposal = true;

                TraceFrame tf = RootTraceFrame;

                if (tf == this)
                {
                    // This is the root
                    if (tf._nextTraceFrame != null)
                    {
                        if (FrameEventMessagesGenerateMode == GenerateTraceFrameEventMessages.GenerateAll || FrameEventMessagesGenerateMode == GenerateTraceFrameEventMessages.ErrorsOnly)
                        {
                            TraceHelper.TraceFrameEvent(TraceFrameEventType.WrongDisposeOrder, this);
                        }
                    }

                    RootTraceFrame = null;
                }
                else
                {
                    // This is not the root

                    while (tf == null || tf._nextTraceFrame != this)
                    {
                        tf = tf._nextTraceFrame;
                    }

                    // We went down the list, but cannot found ourselves -> must never happen.
                    System.Diagnostics.Debug.Assert(tf != null);

                    // Now "tf" points to my parent

                    // I have children - the developer calls the Dispose in wrong order...
                    if (_nextTraceFrame != null)
                    {
                        if (FrameEventMessagesGenerateMode == GenerateTraceFrameEventMessages.GenerateAll || FrameEventMessagesGenerateMode == GenerateTraceFrameEventMessages.ErrorsOnly)
                        {
                            TraceHelper.TraceFrameEvent(TraceFrameEventType.WrongDisposeOrder, this);
                        }
                    }

                    // Ask my parent to kill me. Not PC, but works.
                    tf._nextTraceFrame = null;
                }

                if (FrameEventMessagesGenerateMode == GenerateTraceFrameEventMessages.GenerateAll)
                {
                    TraceHelper.TraceFrameEvent(TraceFrameEventType.Finished, this);
                }

                if (!calledByFinalizer)
                {
                    GC.SuppressFinalize(this);
                }
            }
        }
Ejemplo n.º 3
0
        internal static void TraceFrameEvent(TraceFrameEventType eventType, TraceFrame traceFrame)
        {
            string traceFrameString = TraceFrame.GetTraceFrameString();
            string fullMessage      = string.Concat(traceFrameString, " ", traceFrame.Message, " ", eventType.ToString());

            MethodBase caller = traceFrame.Caller;

            TraceHelper.TraceInformationPrivate(fullMessage, caller);
        }
Ejemplo n.º 4
0
        private static string GetFormattedMessage(string message, string methodSignature)
        {
            string traceFrameString      = TraceFrame.GetTraceFrameString();
            string dateTimeString        = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
            string managedThreadIdString = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString(CultureInfo.InvariantCulture);
            string formattedMessage      = string.Format(CultureInfo.InvariantCulture, "[{0}] '{1}' [{2}] [{3}] [{4}]", traceFrameString, message, methodSignature, dateTimeString, managedThreadIdString);

            return(formattedMessage);
        }
Ejemplo n.º 5
0
        internal static TraceFrame GetLastTraceFrame()
        {
            TraceFrame tf = TraceFrame.RootTraceFrame;

            if (tf == null)
            {
                return(null);
            }

            while (tf._nextTraceFrame != null)
            {
                tf = tf._nextTraceFrame;
            }

            return(tf);
        }
Ejemplo n.º 6
0
        internal static string GetTraceFrameString()
        {
            TraceFrame tf = TraceFrame.RootTraceFrame;

            StringBuilder sb = new StringBuilder("[TF>>");

            while (tf != null)
            {
                sb.Append(tf.Message);
                tf = tf._nextTraceFrame;
                if (tf != null)
                {
                    sb.Append(">>");
                }
            }

            sb.Append("]");

            return(sb.ToString());
        }