当前位置: 首页>>代码示例>>C#>>正文


C# TraceSource.TraceInformation方法代码示例

本文整理汇总了C#中TraceSource.TraceInformation方法的典型用法代码示例。如果您正苦于以下问题:C# TraceSource.TraceInformation方法的具体用法?C# TraceSource.TraceInformation怎么用?C# TraceSource.TraceInformation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TraceSource的用法示例。


在下文中一共展示了TraceSource.TraceInformation方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            EnableSelfSignedCertificates();

            Uri uri = new Uri("https://localhost:8088");
            string token = "BEC47D17-AC4A-49ED-834B-969745D24550";

            var trace = new TraceSource("conf-demo");
            trace.Switch.Level = SourceLevels.All;
            var listener = new HttpEventCollectorTraceListener(uri, token);
            trace.Listeners.Add(listener);

            HashSet<string> files = new HashSet<string>();

            while (true)
            {
                string[] currentFiles = Directory.GetFiles(args[0]);
                foreach (string s in currentFiles)
                {
                    if (!files.Contains(s))
                    {
                        files.Add(s);
                        string ascii = ToAscii(s.Substring(s.LastIndexOf('\\') + 1), new Bitmap(s, true));

                        trace.TraceInformation(ascii);
                        trace.Flush();
                    }
                }
                Thread.Sleep(200);
            }
        }
开发者ID:JianLeeGit,项目名称:playground,代码行数:31,代码来源:Program.cs

示例2: ShouldLogNetworkCommunication

        public void ShouldLogNetworkCommunication()
        {
            // Setup source and listener
            string initializationString =
                @"name = XmlLogger; logrootpath = c:\logs\; staticpattern = lognc_; maxSizeBytes = 200000;";

            XmlWriterRollingTraceListener traceListener =
                new XmlWriterRollingTraceListener(initializationString);

            TraceSource log = new TraceSource("Test", SourceLevels.All);

            log.Listeners.Clear();
            log.Listeners.Add(traceListener);

            // Start Activity #1
            Guid activity1Guid = Guid.NewGuid();

            Trace.CorrelationManager.ActivityId = activity1Guid;

            log.TraceEvent(TraceEventType.Start, 2, "Activity #1");

            // log information inside Activity #1
            log.TraceInformation("Going to execute HttpWebRequest from Activity #1");

            HttpWebRequest request = HttpWebRequest.Create("http://www.google.com/") as HttpWebRequest;
            WebResponse response = request.GetResponse();

            using (StreamReader s = new StreamReader(response.GetResponseStream()))
            {
                string value = s.ReadToEnd();
            }

            // Complete Activity #1
            log.TraceEvent(TraceEventType.Stop, 8, "Completing Activity #1");
        }
开发者ID:alienwaredream,项目名称:toolsdotnet,代码行数:35,代码来源:LoggingTest.cs

示例3: TraceInformationTest

 public void TraceInformationTest()
 {
     var trace = new TraceSource("TestTraceSource", SourceLevels.All);
     var listener = new TestTraceListener();
     trace.Listeners.Add(listener);
     trace.TraceInformation("message");
     Assert.Equal(0, listener.GetCallCount(Method.TraceData));
     Assert.Equal(0, listener.GetCallCount(Method.Write));
     Assert.Equal(1, listener.GetCallCount(Method.TraceEvent));
     trace.TraceInformation("format", "arg1", "arg2");
     Assert.Equal(2, listener.GetCallCount(Method.TraceEvent));
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:12,代码来源:TraceSourceClassTests.cs

示例4: EmailFilterSendFiltered

        public void EmailFilterSendFiltered()
        {
            TraceSource source = new TraceSource("emailFilterSource");

            source.TraceEvent(TraceEventType.Error, 0, "Include Error.");
            source.TraceInformation("Include Info.");
            source.TraceEvent(TraceEventType.Verbose, 0, "Default filter does not include Verbose.");

            System.Threading.Thread.Sleep(2000);//need to wait, otherwise the test host is terminated resulting in thread abort.

            AssertMessagesSent(2);
        }
开发者ID:amccool,项目名称:essentialdiagnostics,代码行数:12,代码来源:EmailTests.cs

示例5: TraceSourceManySimpleStringsTest

        public void TraceSourceManySimpleStringsTest()
        {
            var x = new ElasticSearchTraceListener("tester");
            x.ElasticSearchUri = "http://192.168.2.50:9200";
            x.ElasticSearchTraceIndex = "trace";

            var ts = new TraceSource("x", SourceLevels.All);
            ts.Listeners.Add(x);

            for (int i = 0; i < 10; i++)
            {
                ts.TraceInformation("xxxxx" + i);
            }
            x.Flush();

        }
开发者ID:amccool,项目名称:ElasticSearch.Diagnostics,代码行数:16,代码来源:ESTLUnitTests.cs

示例6: ShouldLogWithXmlRollingListenerNoConfig

        public void ShouldLogWithXmlRollingListenerNoConfig()
        {
            // Setup source and listener
            string initializationString =
                @"name = XmlLogger; logrootpath = c:\logs; staticpattern = log_; maxSizeBytes = 20000;";

            XmlWriterRollingTraceListener traceListener =
                new XmlWriterRollingTraceListener(initializationString);

            TraceSource log = new TraceSource("Test", SourceLevels.All);

            log.Listeners.Clear();
            log.Listeners.Add(traceListener);

            // Start Activity #1
            Guid activity1Guid = Guid.NewGuid();

            Trace.CorrelationManager.ActivityId = activity1Guid;

            log.TraceEvent(TraceEventType.Start, 2, "Activity #1");

            // log information inside Activity #1
            log.TraceInformation("Information from Activity #1");

            // Start Activity #2
            Guid activity2Guid = Guid.NewGuid();

            log.TraceTransfer(3, "Transferring to Activity #2", activity2Guid);

            Trace.CorrelationManager.ActivityId = activity2Guid;

            log.TraceData(TraceEventType.Start, 4, "Activity #2");

            // Complete Activity #2
            log.TraceEvent(TraceEventType.Stop, 5, "Completing Activity #2");

            log.TraceTransfer(6, "Returning back to Activity #1", activity1Guid);

            // Get back into Activity #1
            Trace.CorrelationManager.ActivityId = activity1Guid;
            // Log something extra in Activity #1 before completing it
            log.TraceEvent(TraceEventType.Warning, 7, "Warning from Activity #1");
            // Complete Activity #1
            log.TraceEvent(TraceEventType.Stop, 8, "Completing Activity #1");
        }
开发者ID:alienwaredream,项目名称:toolsdotnet,代码行数:45,代码来源:LoggingTest.cs

示例7: ShouldUseNetCacheCommunication

        public void ShouldUseNetCacheCommunication()
        {
            // Setup source and listener
            string initializationString =
                @"name = XmlLogger; logrootpath = c:\logs\; staticpattern = lognc_; maxSizeBytes = 200000;";

            XmlWriterRollingTraceListener traceListener =
                new XmlWriterRollingTraceListener(initializationString);

            TraceSource log = new TraceSource("Test", SourceLevels.All);

            log.Listeners.Clear();
            log.Listeners.Add(traceListener);

            // Start Activity #1
            Guid activity1Guid = Guid.NewGuid();

            Trace.CorrelationManager.ActivityId = activity1Guid;

            log.TraceEvent(TraceEventType.Start, 2, "Activity #1");

            // log information inside Activity #1
            log.TraceInformation("Going to execute HttpWebRequest from Activity #1");

            HttpWebRequest request = HttpWebRequest.Create("http://www.lenovo.com/i/v15/t/lenovo-mast-logo.gif") as HttpWebRequest;
            WebResponse response = request.GetResponse();

            using (StreamReader s = new StreamReader(response.GetResponseStream()))
            {
                string value = s.ReadToEnd();
            }

            request = HttpWebRequest.Create("http://www.lenovo.com/i/v15/t/lenovo-mast-logo.gif") as HttpWebRequest;
            response = request.GetResponse();

            Assert.IsTrue(response.IsFromCache, "It is expected that this response will be returned from cache");

            using (StreamReader s = new StreamReader(response.GetResponseStream()))
            {
                string value = s.ReadToEnd();
            }

            // Complete Activity #1
            log.TraceEvent(TraceEventType.Stop, 8, "Completing Activity #1");
        }
开发者ID:alienwaredream,项目名称:toolsdotnet,代码行数:45,代码来源:LoggingTest.cs

示例8: VerifyEventsAreInOrder

        static void VerifyEventsAreInOrder()
        {
            string tokenName = "verifyeventsareinordertoken";
            string indexName = "verifyeventsareinorderindex";
            SplunkCliWrapper splunk = new SplunkCliWrapper();
            double testStartTime = SplunkCliWrapper.GetEpochTime();
            string token = CreateIndexAndToken(splunk, tokenName, indexName);

            var trace = new TraceSource("HttpEventCollectorLogger");
            trace.Switch.Level = SourceLevels.All;
            var meta = new HttpEventCollectorEventInfo.Metadata(index: indexName, source: "host", sourceType: "log", host: "customhostname");
            var listener = new HttpEventCollectorTraceListener(
                uri: new Uri("https://127.0.0.1:8088"),
                token: token,
                metadata: meta);
            trace.Listeners.Add(listener);

            // Generate data
            int totalEvents = 1000;
            string[] filer = new string[2];
            filer[0] = new string('s', 1);
            filer[1] = new string('l', 100000);
            for (int i = 0; i < totalEvents; i++)
            {
                trace.TraceInformation(string.Format("TraceInformation. This is event {0}. {1}", i, filer[i%2]));
            }

            string searchQuery = "index=" + indexName;
            Console.WriteLine("{0} events were created, waiting for indexing to complete.", totalEvents);
            splunk.WaitForIndexingToComplete(indexName);
            int eventsFound = splunk.GetSearchCount(searchQuery);
            Console.WriteLine("Indexing completed, {0} events were found. Elapsed time {1:F2} seconds", eventsFound, SplunkCliWrapper.GetEpochTime() - testStartTime);
            // Verify all events were indexed correctly and in order
            Assert.Equal(totalEvents, eventsFound);
            List<string> searchResults = splunk.GetSearchResults(searchQuery);
            Assert.Equal(searchResults.Count, eventsFound);
            for (int i = 0; i< totalEvents; i++)
            {
                int id = totalEvents - i - 1;
                string expected = string.Format("TraceInformation. This is event {0}. {1}", id, filer[id % 2]);
                Assert.True(searchResults[i].Contains(expected));
            }
            trace.Close();
        }
开发者ID:JimSimpkins13,项目名称:splunk-library-dotnetlogging,代码行数:44,代码来源:TestWithSplunk.cs

示例9: GenerateData

 private static int GenerateData(TraceSource trace, int eventsPerLoop = 50)
 {
     int eventCounter = 0, id = 0;
     foreach (TraceEventType eventType in new TraceEventType[] { TraceEventType.Error, TraceEventType.Information, TraceEventType.Warning })
     {
         for (int i = 0; i < eventsPerLoop; i++, id++, eventCounter++)
         {
             trace.TraceData(eventType, id, new string[] { "TraceData", eventType.ToString(), string.Format("This is event {0}", id) });
         }
     }
     foreach (TraceEventType eventType in new TraceEventType[] { TraceEventType.Error, TraceEventType.Information, TraceEventType.Warning })
     {
         for (int i = 0; i < eventsPerLoop; i++, id++, eventCounter++)
         {
             trace.TraceEvent(eventType, id, "TraceEvent " + eventType.ToString() + string.Format(" This is event {0}", id));
         }
     }
     for (int i = 0; i < eventsPerLoop; i++, id++, eventCounter++)
     {
         trace.TraceInformation(string.Format("TraceInformation. This is event {0}", id));
     }
     return eventCounter;
 }
开发者ID:JimSimpkins13,项目名称:splunk-library-dotnetlogging,代码行数:23,代码来源:TestWithSplunk.cs


注:本文中的TraceSource.TraceInformation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。