Click here to Skip to main content
15,895,142 members
Articles / Desktop Programming / XAML

Diagnostic Explorer

Rate me:
Please Sign up or sign in to vote.
4.93/5 (41 votes)
29 Nov 2010LGPL315 min read 82.6K   1.5K   120  
A .NET library and website which allows developers to expose and view arbitrary diagnostic information about their .NET processes.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DiagnosticExplorer;
using System.Threading;
using System.Diagnostics;
using log4net;

namespace WidgetSample
{
	public static class TraceScopeExample
	{
		private static Random _rand = new Random();

		public static void TestTraceScope1()
		{
			using (new TraceScope())
			{
				SmallRandomSleep();

				int times = _rand.Next(1, 3);
				TraceScope.Trace("About to call TestTraceScope2() {0} times", times);
				for (int i = 0; i < times; i++)
					TestTraceScope2();

				TraceScope.Trace("Just called TestTraceScope2()");
			}
		}

		public static void TestTraceScope2()
		{
			using (new TraceScope())
			{
				SmallRandomSleep();

				int times = _rand.Next(1, 3);
				TraceScope.Trace("About to call TestTraceScope3() {0} times", times);
				for (int i = 0; i < times; i++)
					TestTraceScope3();
				TraceScope.Trace("Just called TestTraceScope3()");
			}
		}

		public static void TestTraceScope3()
		{
			using (new TraceScope())
			{
				SmallRandomSleep();
				TraceScope.Trace("About to call TestTraceScope4()");
				TestTraceScope4();
				TraceScope.Trace("Just called TestTraceScope4()");
			}
		}

		public static void TestTraceScope4()
		{
			using (new TraceScope())
			{
				SmallRandomSleep();
				TraceScope.Trace("Your lucky random number is {0}", _rand.Next());
				TraceScope.Trace(@"Heres a multiline trace message
which, as you can see,
has more than one line");
			}
		}

		public static void SmallRandomSleep()
		{
			int sleepMillis = _rand.Next(10, 50);
			TraceScope.Trace("Sleeping {0}", sleepMillis);
			Thread.Sleep(sleepMillis);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer
United Kingdom United Kingdom
I am a software developer originally from Auckland, New Zealand. I have lived and worked in London since 2005.

Comments and Discussions