Exemple #1
0
        /// <summary>
        /// Generates a diagnostic trace of the message passed.
        /// </summary>
        /// <param name="title">The trace title.</param>
        /// <param name="message">The message.</param>
        public static void Trace(string title, SipMessage message)
        {
            StringBuilder sb = new StringBuilder(1024);
            SipRequest    request;
            SipResponse   response;
            string        summary;
            string        contentType;
            SipCSeqValue  vCSeq;
            string        cseqMethod;
            string        cseqNumber;

            vCSeq = message.GetHeader <SipCSeqValue>(SipHeader.CSeq);
            if (vCSeq == null)
            {
                cseqMethod = "????";
                cseqNumber = "CSeq:????";
            }
            else
            {
                cseqMethod = vCSeq.Method;
                cseqNumber = "CSeq:" + vCSeq.Number.ToString();
            }

            request = message as SipRequest;
            if (request != null)
            {
                summary = string.Format("{0} Request: {1} {2}", request.MethodText, request.Uri, cseqNumber);
            }
            else
            {
                response = (SipResponse)message;
                summary  = string.Format("{0} Response: {1} ({2}) {3}", cseqMethod, response.StatusCode, response.ReasonPhrase, cseqNumber);
            }

            sb.AppendLine(title);
            sb.AppendLine();
            sb.Append(message.ToString());

            contentType = message.GetHeaderText(SipHeader.ContentType);
            if (message.ContentLength > 0 && message.HasContentType(SipHelper.SdpMimeType))
            {
                sb.AppendLine(Helper.FromUTF8(message.Contents));
            }
            else
            {
                sb.AppendLine(Helper.HexDump(message.Contents, 16, HexDumpOption.ShowAll));
            }

            NetTrace.Write(SipHelper.TraceSubsystem, 0, "SIP: " + title, summary, sb.ToString());
        }
Exemple #2
0
        /// <summary>
        /// Writes custom information about the exception to the string builder
        /// instance passed which will eventually be written to the event log.
        /// </summary>
        /// <param name="sb">The output string builder.</param>
        /// <remarks>
        /// Implementations of this method will typically write the exception's
        /// stack trace out to the string builder before writing out any custom
        /// information.
        /// </remarks>
        public void Log(StringBuilder sb)
        {
            if (badMessage != null)
            {
                sb.AppendLine("Message:\r\n\r\n");
                sb.Append(badMessage.ToString());
            }

            if (badPacket != null)
            {
                sb.AppendFormat("Transport:     {0}\r\n", transport == null ? "<unknown>" : transport);
                sb.AppendFormat("Packet Source: {0}\r\n\r\n", sourceEP);
                sb.AppendLine("Packet (formatted):");
                sb.AppendLine(Helper.HexDump(badPacket, 16, HexDumpOption.ShowAll));
                sb.AppendLine("");
                sb.AppendLine("Packet (raw):");
                sb.AppendLine(Helper.HexDump(badPacket, 16, HexDumpOption.None));
            }
        }