Esempio n. 1
0
        public ActionResult <long> WatchingMethodStartWithCorrelationIdAndFakeServiceSteps()
        {
            // generate correlationId (for example)
            var correlationId = Guid.NewGuid();

            var parameterForMethod2 = "parameter";

            // start performance watching with correlationId and caller source data
            using (PerformanceMeter <PerformanceMeterController>
                   .WatchingMethod()
                   .WithSettingData
                   .CustomData("corellationId", correlationId)
                   .CallerSourceData()
                   .Start())
            {
                // add step with calling FakeService.FakeMethod2 with custom data (corellationId)
                using (PerformanceMeter <FakeService>
                       .WatchingMethod(nameof(FakeService.FakeMethod1))
                       .WithSettingData
                       .CustomData("corellationId", correlationId)
                       .CustomData("fake service method 1 step", 1)
                       .CallerSourceData()
                       .Start())
                {
                    FakeService.FakeMethod1();
                }

                // add step with calling FakeService.FakeMethod2 with custom data (corellationId and perameter for FakeMethod2)
                using (PerformanceMeter <FakeService>
                       .WatchingMethod(nameof(FakeService.FakeMethod2))
                       .WithSettingData
                       .CustomData("corellationId", correlationId)
                       .CustomData("fake service method 2 step", 2)
                       .CustomData("method parameter", parameterForMethod2)
                       .CallerSourceData()
                       .Start())
                {
                    FakeService.FakeMethod2(parameterForMethod2);
                }
            }

            return(Ok(PerformanceMeter <FakeService> .PerformanceInfo.MethodCalls.Where(mc => mc.MethodName.StartsWith("Fake")).Sum(mc => mc.Elapsed.TotalMilliseconds)));
        }