Ejemplo n.º 1
0
        //----------------------------------------------------------------------

        /// <summary>
        /// Initialize the tracetool EventSink using suplied parameters.
        /// </summary>
        /// <param name="parameters">Parameters for the Event=sink (see eif config file)</param>
        /// <param name="eventSource">event Source</param>
        public TraceToolEventSink(IDictionary parameters, EventSource eventSource) : base(parameters, eventSource)
        {
            EventSourceName = eventSource.Name;

            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            // Use parameters from the eventSink tag
            foreach (Object obj in parameters.Keys)
            {
                string ParamName  = obj.ToString().ToLower();
                string ParamValue = parameters[obj].ToString();

                if (ParamName == "remotehost")
                {
                    TTrace.Options.SocketHost = ParamValue;
                }
                if (ParamName == "remoteport")
                {
                    TTrace.Options.SocketPort = Convert.ToInt32(ParamValue);
                }
                if (ParamName == "wintraceid")
                {
                    winTraceId = ParamValue;
                }
                if (ParamName == "wintracetitle")
                {
                    winTraceTitle = ParamValue;
                }
                if (ParamName == "immediateflush")
                {
                    immediateFlush = Convert.ToBoolean(ParamValue);
                }
                if (ParamName == "sendmode")
                {
                    if (ParamValue.ToLower().CompareTo("winmsg") == 0)
                    {
                        TTrace.Options.SendMode = TraceTool.SendMode.WinMsg;
                    }
                    else if (ParamValue.ToLower().CompareTo("socket") == 0)
                    {
                        TTrace.Options.SendMode = TraceTool.SendMode.Socket;
                    }
                }
                if (ParamName == "logfile")
                {
                    int pos = ParamValue.IndexOf(',');
                    try
                    {
                        logFileName = ParamValue.Substring(pos + 1);
                        logMode     = Int32.Parse(ParamValue.Substring(0, pos));
                    }
                    catch
                    {
                        // no error
                    }
                }
            }

            if (this.winTraceId != null || this.winTraceTitle != null)
            {
                this.log4WinTrace = new WinTrace(this.winTraceId, this.winTraceTitle);
            }
            else
            {
                this.log4WinTrace = TTrace.WinTrace;
            }

            if (this.logMode >= 0)
            {
                this.log4WinTrace.SetLogFile(this.logFileName, this.logMode);
            }
        }
Ejemplo n.º 2
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
            }
        }