コード例 #1
0
        public static PerformanceTimerAttribute GetPerformanceTimer(ClassificationDeclaration classificationDeclaration)
        {
            var timer = PerformanceTimerAttribute.StartNew(
                RollbarPerformanceMonitor.Instance,
                PerformanceUtil.GetClassification(classificationDeclaration)
                );

            return(timer);
        }
コード例 #2
0
        private void EvaluateLogMethod(ClassificationDeclaration classificationDeclaration)
        {
            RollbarConfig loggerConfig = ProvideRollbarConfig();

            object payload = null;

            switch (classificationDeclaration.PayloadType)
            {
            case PayloadType.Message:
            {
                payload = ProvideObjectToLog(classificationDeclaration);
            }
            break;

            case PayloadType.Exception:
            {
                payload = ProvideObjectToLog(classificationDeclaration);
            }
            break;

            default:
                break;
            }
            Assert.IsNotNull(payload);

            // Let's give things change to stabilize:
            //Thread.Sleep(TimeSpan.FromSeconds(2));

            using (var rollbar = RollbarFactory.CreateNew().Configure(loggerConfig))
            {
                for (int i = 0; i < Constants.TotalMeasurementSamples; i++)
                {
                    switch (classificationDeclaration.MethodVariant)
                    {
                    case MethodVariant.Async:
                    {
                        IAsyncLogger logger = rollbar;
                        using (PerformanceUtil.GetPerformanceTimer(classificationDeclaration))
                        {
                            logger.Log(ErrorLevel.Warning, payload);
                        }
                        break;
                    }

                    case MethodVariant.AsyncWaited:
                    {
                        IAsyncLogger logger = rollbar;
                        using (PerformanceUtil.GetPerformanceTimer(classificationDeclaration))
                        {
                            logger.Log(ErrorLevel.Warning, payload).Wait();
                        }
                        break;
                    }

                    case MethodVariant.Blocking:
                    {
                        // NOTE: for blocking call we want to eliminate effect of
                        // the max reporting rate restriction, so that the wait time
                        // that is a result of the rate limit is not counted against
                        // the blocking call:
                        BlockUntilRollbarQueuesAreEmpty();
                        Thread.Sleep(TimeSpan.FromSeconds(60 / rollbar.Config.MaxReportsPerMinute));

                        ILogger logger = rollbar.AsBlockingLogger(Constants.RollbarBlockingTimeout);
                        using (PerformanceUtil.GetPerformanceTimer(classificationDeclaration))
                        {
                            logger.Log(ErrorLevel.Critical, payload);
                        }
                        break;
                    }

                    default:
                        // nothing to do...
                        break;
                    }
                }

                //BlockUntilRollbarQueuesAreEmpty();
                //Thread.Sleep(TimeSpan.FromMilliseconds(250));
                //if (classificationDeclaration.MethodVariant == MethodVariant.Async)
                //{
                //    // NOTE: for async call we want to make sure the logger's instance is not
                //    // disposed until all the buffered payloads delivered to the Rollbar API.
                //    // This delay ios needed until issue #197 is resolved...
                //    BlockUntilRollbarQueuesAreEmpty();
                //}
            }
        }