|
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.
I am a software developer originally from Auckland, New Zealand. I have lived and worked in London since 2005.