Пример #1
0
        static Stream CreateTraceXml()
        {
            MemoryStream result = null;
            MemoryStream ms     = null;

            try
            {
                ms = new MemoryStream();
                using (XmlWriter writer = XmlWriter.Create(ms, new XmlWriterSettings {
                    OmitXmlDeclaration = true
                }))
                {
                    writer.WriteStartElement("Traces");
                    foreach (XElement element in InMemoryTraceListener.GetEntries())
                    {
                        element.WriteTo(writer);
                    }
                    writer.WriteEndElement();
                }
                ms.Seek(0, SeekOrigin.Begin);

                result = ms;
                ms     = null;
            }
            finally
            {
                if (ms != null)
                {
                    ms.Dispose();
                }
            }
            return(result);
        }
Пример #2
0
        static SyndicationFeed CreateTraceSyndicationFeed()
        {
            IEnumerable <SyndicationItem> items = from entry in InMemoryTraceListener.GetEntries()
                                                  select CreateTraceSyndicationItem(entry);

            SyndicationFeed feed = new SyndicationFeed(items);

            feed.Title = new TextSyndicationContent(Resx.WCFTraceFeedTitle);
            return(feed);
        }
Пример #3
0
        static Stream CreateTraceHtml()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(string.Format(CultureInfo.InvariantCulture, "<html><head><title>{0}</title></head><body style=\"font-family: sans-serif\"><h1>{0}</h1>", Resx.WCFTraceFeedTitle));
            IEnumerable <string> items = from entry in InMemoryTraceListener.GetEntries()
                                         select CreateTraceHtmlEntry(entry);

            foreach (string item in items)
            {
                sb.Append(item);
            }
            sb.Append("</body></html>");
            return(new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString())));
        }
 public void GetEntriesTest()
 {
     XElement[] actual;
     InMemoryTraceListener_Accessor.entries = new System.Collections.Concurrent.ConcurrentQueue<XElement>();
     InMemoryTraceListener target = new InMemoryTraceListener();
     target.Write("System.ServiceModel Information: 1 : ");
     target.WriteLine("<TraceRecord xmlns=\"http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord\" Severity=\"Information\"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Security.SecurityImpersonationSuccess.aspx</TraceIdentifier><Description>Security Impersonation succeeded at the server.</Description><AppDomain>/LM/W3SVC/1/ROOT/riatracing-1-129141143812693125</AppDomain><ExtendedData xmlns=\"http://schemas.microsoft.com/2006/08/ServiceModel/SecurityImpersonationTraceRecord\"><OperationAction>http://tempuri.org/WcfTraceService/GetTrace</OperationAction><OperationName>GetTrace</OperationName></ExtendedData></TraceRecord>");
     target.Write("System.ServiceModel Information: 2 : ");
     target.WriteLine("");
     target.WriteLine("<TraceRecord xmlns=\"http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord\" Severity=\"Information\"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Security.SecurityImpersonationSuccess.aspx</TraceIdentifier><Description>Security Impersonation succeeded at the server.</Description><AppDomain>/LM/W3SVC/1/ROOT/riatracing-1-129141143812693125</AppDomain><ExtendedData xmlns=\"http://schemas.microsoft.com/2006/08/ServiceModel/SecurityImpersonationTraceRecord\"><OperationAction>http://tempuri.org/WcfTraceService/GetTrace</OperationAction><OperationName>GetTrace</OperationName></ExtendedData></TraceRecord>");
     target.Write("boo");
     target.WriteLine("foobarbaz");
     target.Write("System.ServiceModel Information: 3 : ");
     target.WriteLine("<TraceRecord xmlns=\"http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord\" Severity=\"Information\"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Security.SecurityImpersonationSuccess.aspx</TraceIdentifier><Description>Security Impersonation succeeded at the server.</Description><AppDomain>/LM/W3SVC/1/ROOT/riatracing-1-129141143812693125</AppDomain><ExtendedData xmlns=\"http://schemas.microsoft.com/2006/08/ServiceModel/SecurityImpersonationTraceRecord\"><OperationAction>http://tempuri.org/WcfTraceService/GetTrace</OperationAction><OperationName>GetTrace</OperationName></ExtendedData></TraceRecord>");
     actual = InMemoryTraceListener_Accessor.GetEntries();
     Assert.IsNotNull(actual);
     Assert.IsTrue(actual.Length == 3);
     int lastEntryCode = 4;
     foreach (XElement entry in actual)
     {
         int currentEntryCode = Int32.Parse(entry.Descendants().First(x => x.Name.LocalName == "Code").Value);
         Assert.IsTrue(currentEntryCode < lastEntryCode);
         lastEntryCode = currentEntryCode;
     }
 }
 public void InMemoryTraceListenerConstructorTest()
 {
     string name = "foo";
     InMemoryTraceListener target = new InMemoryTraceListener(name);
     Assert.IsTrue(target.Name == name);
 }