コード例 #1
0
ファイル: TraceToSend.cs プロジェクト: capslock66/Tracetool
        //----------------------------------------------------------------------
        /// <summary>
        /// Send the Value of the given object (useful for base type, variant and array)
        /// </summary>
        /// <param name="leftMsg">the message to display</param>
        /// <param name="objToSend">The object to show</param>
        /// <param name="sendPrivate">Send Private fields (default is false)</param>
        /// <param name="maxLevel">Max level to inspect (default is 3)</param>
        /// <param name="objTitle">Title of the object</param>
        /// <returns>the new node</returns>
        public TraceNode SendValue(string leftMsg, Object objToSend, bool sendPrivate, int maxLevel, string objTitle)
        {
            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);

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

            TTrace.SendToWinTraceClient(commandList, WinTraceId);
            return(new TraceNode(result));
        }
コード例 #2
0
ファイル: WinWatch.cs プロジェクト: capslock66/Tracetool
        //------------------------------------------------------------------------------

        /// <summary>
        /// Send a watch
        /// </summary>
        /// <param name="watchName">Watch name</param>
        /// <param name="watchValue">Watch value</param>
        public void Send(string watchName, object watchValue)
        {
            if (Enabled == false)
            {
                return;
            }

            List <string> commandList = new List <string>();

            commandList.Insert(0, String.Format("{0,5}{1}", TraceConst.CST_WATCH_NAME, watchName));

            // create a node with same properties as "self" with new ID
            TraceNodeEx node = new TraceNodeEx(null, false);                                           // no parent, don't generate node id

            node.AddValue(watchValue, TTrace.Options.SendPrivate, TTrace.Options.ObjectTreeDepth, ""); // sendPrivate true , max 3 levels, no title
            node.Members.AddToStringList(commandList);                                                 // convert all groups and nested items/group to strings

            TTrace.SendToWinWatchClient(commandList, Id);
        }
コード例 #3
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
            }
        }