Example #1
0
 private static void DemoTraceScopeToConsole()
 {
     // hook up console writer/logger for this demo!
     var Tracer = new Tracing.Tracer(category: new string[] { "DemoTraceScopeToConsole" });
     Tracer.OnLog += Tracer_OnLog;
     Tracer.OnException += Tracer_OnException;
     using (new Tracing.TraceScope(Tracer, "Foo()"))
     {
         // invoke Foo via Tracer to generate code tracing useful logs on Enter, [on Exit].
         // run time measurement is also logged on generated "on Exit" logs.
         Foo();
     }
     // invoke FooThatThrows.
     var i = 123;
     try
     {
         using (new Tracing.TraceScope(Tracer, string.Format("FooThatThrows({0})", i),
             InvokeVerbosity.OnEnter))
         {
             FooThatThrows(i);
             // NOTE: OnLeave will not be invoked (i.e. - no OnLeave log generated)
             // because verbosity is set to "OnEnter" only.
         }
     }
     catch
     {
         Console.WriteLine("Caught an exception.");
     }
 }
Example #2
0
 private static void DemoTracerWithScopeAndResultEval()
 {
     // Shows how to dictate generated log message using a ResultsEvaluator.
     var Tracer = new Tracing.Tracer(new string[] { "DemoTracerWithScopeAndResultEval" }, resultEval);
     Tracer.OnLog += Tracer_OnLog;
     Tracer.OnException += Tracer_OnException;
     using (new Tracing.TraceScope(Tracer, "FooTakesTime(4)"))
     {
         FooTakesTime(4);
     }
 }
Example #3
0
        private static void DemoTracerToConsole()
        {
            // hook up console writer/logger for this demo!
            var Tracer = new Tracing.Tracer(category: new string[] { "DemoTracerToConsole" });
            Tracer.OnLog += Tracer_OnLog;
            Tracer.OnException += Tracer_OnException;
            // invoke Foo via Tracer to generate code tracing useful logs on Enter, [on Exit], [on Exception].
            // run time measurement is also logged on generated "on Exit" logs.
            Tracer.Invoke(Foo, funcFootprint: "Foo()");

            // invoke FooThatThrows.
            var i = 123;
            Tracer.Invoke(FooThatThrows, i, InvokeVerbosity.OnEnter,
                funcFootprint: string.Format("FooThatThrows({0})", i));
        }
Example #4
0
        private static void DemoTraceScopeUsingSingletonTracer()
        {
            // hook up console writer/logger for this demo!
            var Tracer = new Tracing.Tracer(category: new string[] { "DemoTraceScopeUsingSingletonTracer" });
            Tracer.OnLog += Tracer_OnLog;
            Tracer.OnException += Tracer_OnException;
            // Call SetTracer to setup singleton Tracer Instance.
            // Setting up the singleton Tracer needs to be done once in App bootup.
            Tracing.Tracer.SetTracer(Tracer);

            // Using Tracing.TraceScope passing no Tracer instance param
            // will use the singleton Tracer instance.
            using (new Tracing.TraceScope("Foo()"))
            {
                // invoke Foo via Tracer to generate code tracing useful logs on Enter.
                // run time measurement is also logged on generated "on Exit" logs.
                Foo();
            }
            // invoke FooThatThrows.
            var i = 123;
            try
            {
                using (new Tracing.TraceScope(string.Format("FooThatThrows({0})", i)))
                {
                    FooThatThrows(i);
                }
            }
            catch
            {
                Console.WriteLine("Caught an exception.");
            }
        }