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


C# TraceSource.TraceEvent方法代码示例

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


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

示例1: EmailFloodManyThreadsMax100

        public void EmailFloodManyThreadsMax100()
        {
            TraceSource source = new TraceSource("emailFlood2Source");

            Action d = () =>
            {
                try
                {
                    var guid = Guid.NewGuid();
                    source.TraceEvent(TraceEventType.Warning, 0, "Message 1 - {0}", guid);
                    source.TraceEvent(TraceEventType.Error, 0, "Message 2 - {0}", guid);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Action exception: {0}", ex));
                }
            };

            for (int i = 0; i < 200; i++)
            {
                d.BeginInvoke(null, null);
            }

            // Need to wait, otherwise messages haven't been sent and Assert throws exception
            System.Threading.Thread.Sleep(3000);

            AssertMessagesSent(100, "Should be limited by max traces of 100.");
        }
开发者ID:amccool,项目名称:essentialdiagnostics,代码行数:28,代码来源:EmailTests.cs

示例2: Run

		public override void Run()
		{
			try
			{
				var m = Helper.FormatTrace("Staring the Scheduler", "SchedulerWorkerRole", "Run");
				var traceSource = new TraceSource("VirtoCommerce.ScheduleService.Trace");
				traceSource.TraceEvent(TraceEventType.Information, 0, m);

				string cloudContext;
				if (RoleEnvironment.IsAvailable)
				{
					cloudContext = String.Format("{0}|{1}",
						RoleEnvironment.DeploymentId,
						RoleEnvironment.CurrentRoleInstance.Id);
				}
				else
				{
					cloudContext = Guid.NewGuid().ToString();
				}

				var jobScheduler = new JobScheduler(cloudContext, traceSource, () => AzureConfiguration.Instance.AzureStorageAccount, new Settings());

                traceSource.TraceEvent(TraceEventType.Information, 0, Helper.FormatTrace("Staring the Scheduler", "SchedulerWorkerRole", "Run", "Starting Paralel.Invoke", cloudContext));

				Parallel.Invoke(
					jobScheduler.JobsManagerProcess,
					jobScheduler.SchedulerProcess);
			}
			catch (Exception ex)
			{
				var m = Helper.FormatException(ex, "WorkerRole", "Run");
				var traceSource = new TraceSource("VirtoCommerce.ScheduleService.Trace");
				traceSource.TraceEvent(TraceEventType.Error, 0, m);
			}
		}
开发者ID:gitter-badger,项目名称:vc-community-1.x,代码行数:35,代码来源:SchedulerWorkerRole.cs

示例3: 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

示例4: Enter

 internal static void Enter(TraceSource source, string method)
 {
     if(source.Switch.ShouldTrace(TraceEventType.Verbose))
     {
         source.TraceEvent(TraceEventType.Verbose, 0, "Entering --> " + method);
     }
 }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:7,代码来源:Logging.cs

示例5: 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

示例6: TestTcpTraceListener

        public async Task TestTcpTraceListener()
        {
            var listener = new TcpListener(IPAddress.Loopback, 0);
            listener.Start();
            int port = ((IPEndPoint)listener.Server.LocalEndPoint).Port;


            var traceSource = new TraceSource("UnitTestLogger");
            traceSource.Listeners.Remove("Default");
            traceSource.Switch.Level = SourceLevels.All;
            traceSource.Listeners.Add(new TcpTraceListener(
                                            IPAddress.Loopback, port, 
                                            new ExponentialBackoffTcpReconnectionPolicy()));

            var listenerClient = await listener.AcceptTcpClientAsync();

            traceSource.TraceEvent(TraceEventType.Information, 100, "Boris");

            var receiverReader = new StreamReader(listenerClient.GetStream());
            var line = await receiverReader.ReadLineAsync();

            Assert.True(line.EndsWith("UnitTestLogger Information: 100 : Boris"));

            listenerClient.Close();
            listener.Stop();
            traceSource.Close();
        }
开发者ID:JimSimpkins13,项目名称:splunk-library-dotnetlogging,代码行数:27,代码来源:TestTcp.cs

示例7: TraceInternal

        private static void TraceInternal(TraceSource traceSource, int eventId, TraceLevel traceLevel, string message)
        {
            if (traceSource == null) 
                return;

            var traceEventType = ConvertTraceLevelToTraceEventType(traceLevel);
            traceSource.TraceEvent(traceEventType, eventId, message);
        }
开发者ID:p69,项目名称:magellan-framework,代码行数:8,代码来源:TraceExtensions.cs

示例8: Main

        static void Main(string[] args)
        {
            var traceSource = new TraceSource("UnitTestLogger");
            traceSource.Listeners.Remove("Default");
            traceSource.Switch.Level = SourceLevels.All;
            traceSource.Listeners.Add(
                new TcpTraceListener(IPAddress.Loopback, 10000,
                                     new ExponentialBackoffTcpReconnectionPolicy()));

            for (int i = 0; i < 10; i++)
                traceSource.TraceEvent(TraceEventType.Information, 100, string.Format("Boris {0}", i));
        }
开发者ID:spacewrangler,项目名称:splunk-library-dotnetlogging,代码行数:12,代码来源:Program.cs

示例9: CloseTest

        public void CloseTest()
        {
            var trace = new TraceSource("T1", SourceLevels.All);
            trace.Listeners.Clear();

            var listener = new TestTraceListener();
            trace.Listeners.Add(listener);
            trace.Close();
            // NOTE: this assertion fails on .net 4.5
            // where TraceSource.Close calls TraceListener.Close, not Dispose.
            Assert.Equal(1, listener.GetCallCount(Method.Dispose));
            // Assert that writing to a closed TraceSource is not an error.
            trace.TraceEvent(TraceEventType.Critical, 0);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:14,代码来源:TraceSourceClassTests.cs

示例10: TestUdpTraceListener

        public async Task TestUdpTraceListener()
        {
            int port = 11000;
            var udpclient = new UdpClient(port);

            var traceSource = new TraceSource("UnitTestLogger");
            traceSource.Listeners.Remove("Default");
            traceSource.Switch.Level = SourceLevels.All;
            traceSource.Listeners.Add(new UdpTraceListener(IPAddress.Loopback, port));
            
            traceSource.TraceEvent(TraceEventType.Information, 100, "Boris");

            var dgram = await udpclient.ReceiveAsync();
            var receivedText = Encoding.UTF8.GetString(dgram.Buffer);
            Assert.Equal("UnitTestLogger Information: 100 : ", receivedText);

            dgram = await udpclient.ReceiveAsync();
            receivedText = Encoding.UTF8.GetString(dgram.Buffer);
            Assert.Equal("Boris\r\n", receivedText);

            udpclient.Close();
            traceSource.Close();
        }
开发者ID:JimSimpkins13,项目名称:splunk-library-dotnetlogging,代码行数:23,代码来源:TestUdp.cs

示例11: EmailSendIntermittent

        public void EmailSendIntermittent()
        {
            TraceSource source = new TraceSource("emailSource");

            Debug.WriteLine("Expect 1");
            source.TraceEvent(TraceEventType.Warning, 0, "Message 1");
            Debug.WriteLine("Expect 2");
            source.TraceEvent(TraceEventType.Error, 0, "Message 2");
            source.TraceEvent(TraceEventType.Error, 0, "Message 3");
            source.TraceEvent(TraceEventType.Error, 0, "Message 4");

            Thread.Sleep(300);
            source.TraceEvent(TraceEventType.Warning, 0, "Message 5");
            Thread.Sleep(150);
            Debug.WriteLine("Expect 1");
            Thread.Sleep(150);
            source.TraceEvent(TraceEventType.Warning, 0, "Message 6");
            Thread.Sleep(300);
            source.TraceEvent(TraceEventType.Warning, 0, "Message 7");

            Thread.Sleep(450);
            Debug.WriteLine("Expect 0");
            Thread.Sleep(450);

            Debug.WriteLine("Expect 1");
            source.TraceEvent(TraceEventType.Warning, 0, "Message 8");
            Thread.Sleep(300);
            source.TraceEvent(TraceEventType.Warning, 0, "Message 9");
            Thread.Sleep(300);
            source.TraceEvent(TraceEventType.Warning, 0, "Message 10");

            Debug.WriteLine("Expect 2");
            source.TraceEvent(TraceEventType.Warning, 0, "Message 11");
            source.TraceEvent(TraceEventType.Warning, 0, "Message 12");

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

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

示例12: TraceEvent3Test

 public void TraceEvent3Test()
 {
     var trace = new TraceSource("TestTraceSource", SourceLevels.All);
     var listener = GetTraceListener();
     trace.Listeners.Add(listener);
     trace.TraceEvent(TraceEventType.Verbose, 0, "Format", "Arg1", "Arg2");
     Assert.Equal(1, listener.GetCallCount(Method.TraceEvent));
     var flushExpected = AutoFlush ? 1 : 0;
     Assert.Equal(flushExpected, listener.GetCallCount(Method.Flush));
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:TraceSourceClassTests.cs

示例13: TraceEvent1Test

 public void TraceEvent1Test()
 {
     var trace = new TraceSource("TestTraceSource", SourceLevels.All);
     var listener = GetTraceListener();
     trace.Listeners.Add(listener);
     trace.TraceEvent(TraceEventType.Verbose, 0);
     Assert.Equal(1, listener.GetCallCount(Method.TraceEvent));
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:8,代码来源:TraceSourceClassTests.cs

示例14: SwitchLevelTest

 public void SwitchLevelTest(SourceLevels sourceLevel, TraceEventType messageLevel, int expected)
 {
     var trace = new TraceSource("TestTraceSource");
     var listener = new TestTraceListener();
     trace.Listeners.Add(listener);
     trace.Switch.Level = sourceLevel;
     trace.TraceEvent(messageLevel, 0);
     Assert.Equal(expected, listener.GetCallCount(Method.TraceEvent));
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:9,代码来源:TraceSourceClassTests.cs

示例15: 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


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