示例#1
0
        //------------------------------------------------------------------------------

        /// <summary>
        /// Delete indentation to the node added by indent()
        /// </summary>
        /// <param name="leftMsg">Message to send to close indentation (optional)</param>
        /// <param name="rightMsg">Message to send to close indentation (optional)</param>
        /// <param name="backGroundColor">RGB background color (optional)(see Color.ToArgb function)</param>
        /// <param name="isExit">if true, viewer type 'exit' is used</param>
        public void UnIndent(String leftMsg, String rightMsg, int backGroundColor, bool isExit)
        {
            if (Enabled == false)
            {
                return;
            }

            DeleteLastContext();

            if (leftMsg != null || rightMsg != null)
            {
                String nodeId = Helper.NewGuid().ToString();  // then give new ID

                List <string> commandList = PrepareNewNode(leftMsg, nodeId);

                if (rightMsg != null)
                {
                    Helper.AddCommand(commandList, TraceConst.CST_RIGHT_MSG, rightMsg);    // param : right string
                }
                if (backGroundColor != -1)
                {
                    Helper.AddCommand(commandList, TraceConst.CST_BACKGROUND_COLOR, Helper.ARGB_to_BGR(backGroundColor), "-1");      // param : color, colId
                }
                if (isExit)
                {
                    TMemberNode member = new TMemberNode();                     // create root member
                    member.Add("").ViewerKind = TraceConst.CST_VIEWER_EXIT;     // then add an empty member with special viewer
                    member.AddToStringList(commandList);                        // convert all groups and nested items/group to strings
                }
                TTrace.SendToWinTraceClient(commandList, WinTraceId);
            }
        }
示例#2
0
        //----------------------------------------------------------------------

        /// <summary>
        /// Send a 'reflected' representation of the given type
        /// </summary>
        /// <param name="leftMsg">The message to display</param>
        /// <param name="oType">The type to inspect</param>
        /// <param name="flags">flags to limit information to send</param>
        /// <returns>the new node</returns>
        public TraceNode SendType(string leftMsg, Type oType, TraceDisplayFlags flags)
        {
            if (Enabled == false)
            {
                return(new TraceNode(this));
            }

            TraceNodeEx result = new TraceNodeEx(this, true);  // create a node with same properties as "this" with new ID

            List <string> commandList = PrepareNewNode(leftMsg, result.Id);

            // detect null type
            if (oType == null)
            {
                TMemberNode node = new TMemberNode("Null Type")
                {
                    ViewerKind = TraceConst.CST_VIEWER_OBJECT
                };
                result.Members.Add(node);
                result.Members.AddToStringList(commandList);
                TTrace.SendToWinTraceClient(commandList, WinTraceId);
                return(new TraceNode(result));
            }

            // information are added to the Members array of the new created object the actual object
            // the current instance can be the public 'Warning' node for example used by multi thread application
            result.AddTypeObject(null, oType, flags);
            result.Members.AddToStringList(commandList); // convert all groups and nested items/group to strings

            TTrace.SendToWinTraceClient(commandList, WinTraceId);
            return(new TraceNode(result));
        }
示例#3
0
        //------------------------------------------------------------------------------

        /// <summary>
        /// Send a message. further trace to the same node are indented under this one.
        /// </summary>
        /// <param name="leftMsg">Left message to send</param>
        /// <param name="rightMsg">Right message to send</param>
        /// <param name="backGroundColor">BackGround Color</param>
        /// <param name="isEnter">if true , a special "enter" icon is added on the node</param>
        public TraceNode Indent(string leftMsg, string rightMsg, int backGroundColor, bool isEnter)
        {
            if (Enabled == false)
            {
                return(null);
            }
            string thId = Helper.GetCurrentThreadId();


            NodeContext newContext = new NodeContext
            {
                ThreadId = thId,
                NodeId   = Helper.NewGuid().ToString()
            };

            TraceNode result = new TraceNode(this)
            {
                Id = newContext.NodeId
            };

            List <string> commandList = new List <string>();
            NodeContext   lastContext = GetLastContext();

            if (lastContext == null)
            {
                //newContext.level = 1 ;
                Helper.AddCommand(commandList, TraceConst.CST_NEW_NODE, Id);              // param : parent Node id
            }
            else
            {                                                                                // context already exist
               //newContext.level = lastContext.level + 1 ;
                Helper.AddCommand(commandList, TraceConst.CST_NEW_NODE, lastContext.NodeId); // param : parent Node id
            }

            Helper.AddCommand(commandList, TraceConst.CST_TRACE_ID, newContext.NodeId);    // param : Node Id
            Helper.AddCommand(commandList, TraceConst.CST_LEFT_MSG, leftMsg);              // param : left string

            if (!string.IsNullOrEmpty(rightMsg))
            {
                Helper.AddCommand(commandList, TraceConst.CST_RIGHT_MSG, rightMsg);        // param : right string
            }
            if (backGroundColor != -1)
            {
                Helper.AddCommand(commandList, TraceConst.CST_BACKGROUND_COLOR, Helper.ARGB_to_BGR(backGroundColor), "-1");      // param : color, colId
            }
            if (isEnter)
            {
                TMemberNode member = new TMemberNode();                     // create root member
                member.Add("").ViewerKind = TraceConst.CST_VIEWER_ENTER;    // then add an empty member with special viewer
                member.AddToStringList(commandList);                        // convert all groups and nested items/group to strings
            }

            Helper.AddCommand(commandList, TraceConst.CST_ICO_INDEX, IconIndex);          // param : icon index
            TTrace.SendToWinTraceClient(commandList, WinTraceId);

            PushContext(newContext);
            return(result);
        }
示例#4
0
 //----------------------------------------------------------------------
 /// <summary>
 /// Add a member to the members list
 /// </summary>
 /// <param name="member"></param>
 /// <returns>The TMember node to add</returns>
 public TMemberNode Add(TMemberNode member)
 {
     Members.Add(member);
     return(member);
 }
示例#5
0
        //----------------------------------------------------------------------
        /// <summary>
        /// Writes the logging event to the TraceTool system.
        /// </summary>
        /// <param name="loggingEvent">The event to log.</param>
        protected override void Append(LoggingEvent loggingEvent)
        {
            try
            {
                // if null then first append.
                if (this.log4WinTrace == null)
                {
                    if (this.winTraceId != null || this.winTraceTitle != null)
                    {
                        this.log4WinTrace = new WinTrace(this.winTraceId, this.winTraceTitle);
                        if (this.Layout != null)
                        {
                            this.log4WinTrace.SetMultiColumn();
                        }
                    }
                    else
                    {
                        // no wintrace specified

                        if (this.Layout != null)
                        {
                            // Layout on main trace window. create a brother main wintrace
                            this.log4WinTrace = new WinTrace("_", "_");
                            this.log4WinTrace.SetMultiColumn();                                // must be specified before setting titles
                        }
                        else
                        {                          // no layout and no wintrace specified, use main wintrace
                            this.log4WinTrace = TTrace.WinTrace;
                        }
                    }

                    if (this.titleLayout != null && this.log4WinTrace != TTrace.WinTrace)
                    {
                        this.log4WinTrace.SetColumnsTitle(this.titleLayout);
                    }

                    if (this.logMode >= 0)
                    {
                        this.log4WinTrace.SetLogFile(this.logFileName, this.logMode);
                    }
                }
                TraceNodeEx node = new TraceNodeEx(this.log4WinTrace.Debug);

                // if layout is used, fill only the leftMsg.
                if (this.Layout != null)
                {
                    node.LeftMsg = RenderLoggingEvent(loggingEvent); //  1.2.0 beta8 and 1.2.9 beta
                    //node.LeftMsg =  this.Layout.Format (loggingEvent) ; // 1.2.0 b8
                    node.Time       = "";                            // blank time //$NON-NLS-1$
                    node.ThreadName = "";                            // blank thread name //$NON-NLS-1$
                }
                else
                {
                    // no layout. Use tracetool columns

                    node.LeftMsg    = loggingEvent.LoggerName;
                    node.RightMsg   = loggingEvent.RenderedMessage;
                    node.ThreadName = loggingEvent.ThreadName;
                    node.Time       = loggingEvent.TimeStamp.ToString("HH:mm:ss:fff");

                    // to do : change icon
                    //int level = event.getLevel ().toInt () ;
                    //String levelstr = event.getLevel ().toString () ;
                    //node.iconIndex = 8 ;
                }

                // add the message object if not a primitive
                Object msg = loggingEvent.MessageObject;
                if (!(msg is string))
                {
                    node.AddValue(msg, this.sendPrivateObjectInfo, 3, "Trace Object");
                }

                // add throwable info, if any
                // GetExceptionStrRep is Obsolete but is keept for previous version compatibility  (1.2.0)
                // string strException = loggingEvent.GetExceptionString ();
                string strException = loggingEvent.GetExceptionStrRep();
                if (strException != "")
                {
                    TMemberNode localInfo = node.Members.Add("Exception informations");

                    string [] split = strException.Split(new Char[] { '\n', '\r' });
                    foreach (string s in split)
                    {
                        if (s.Trim() != "")
                        {
                            localInfo.Add(s);
                        }
                    }
                }

                // send Local information.
                if (this.sendLocationInfo)
                {
                    TMemberNode  localInfo = node.Members.Add("LocalInfo");
                    LocationInfo locInfo   = loggingEvent.LocationInformation;
                    localInfo.Add(locInfo.FileName, locInfo.MethodName, locInfo.LineNumber);
                }

                // finally send the node
                node.Send();

                if (this.immediateFlush)
                {
                    TTrace.Flush();
                }
            }
            catch
            {
                // eat exception
            }
        }