コード例 #1
0
ファイル: Program.cs プロジェクト: BeezUP/Rollbar.NET
            public void DemonstrateStateCapture()
            {
                var criticalObj = new InstanceType();

                criticalObj.AutoProperty = -100;

                try
                {
                    ///...
                    /// oh, no - we have an exception:
                    throw new System.Exception("An exception with state capture!");
                    ///...
                }
                catch (System.Exception ex)
                {
                    // capture state of this instance:
                    var state = RollbarAssistant.CaptureState(this, "Self");
                    // also, capture state of some other critical object:
                    state = new Dictionary <string, object>(state.Concat(RollbarAssistant.CaptureState(criticalObj, nameof(criticalObj))));
                    // also, capture current state of a static type:
                    state = new Dictionary <string, object>(state.Concat(RollbarAssistant.CaptureState(typeof(StaticType))));

                    // report the captured states along with the caught exception:
                    //RollbarLocator.RollbarInstance.AsBlockingLogger(TimeSpan.FromMilliseconds(10000)).Error(ex, state);
                    RollbarLocator.RollbarInstance.Error(ex, state);
                }
            }
コード例 #2
0
        private static void DemonstrateExceptionSourceStateCapture()
        {
            Vehicle vehicle = new Sedan(200)
            {
                Brand = "Audi",
                Model = "A4 Quattro",
                Type  = Sedan.SedanType.PassengerCar,
            };

            try
            {
                vehicle.Start();
            }
            catch (System.Exception ex)
            {
                // capture state of vehicle instance:
                var state = RollbarAssistant.CaptureState(vehicle, "StartedVehicle");
                // also, capture state of the Game static type:
                RollbarAssistant.CaptureState(typeof(Game), state);
                // report the captured states along with the caught exception:
                RollbarLocator.RollbarInstance
                .AsBlockingLogger(TimeSpan.FromMilliseconds(10000))
                .Error(new ApplicationException("Application exception with a state capture.", ex), state);
            }
        }
コード例 #3
0
        public void TestCaptureStateOfStaticType()
        {
            var stateVars = RollbarAssistant.CaptureState(typeof(StaticType));

            Assert.AreEqual(4, stateVars.Count);

            foreach (var key in stateVars.Keys)
            {
                Console.WriteLine($"{key} = {stateVars[key]}");
            }
        }
コード例 #4
0
        void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            var state = RollbarAssistant.CaptureState(this, "Self");

            RollbarLocator.RollbarInstance.Error(e.Exception, new Dictionary <string, object>()
            {
                ["version"] = Settings.Version.ToString()
            });

            MessageBox.Show("This crash will be automatically sended to author", "The application is crashed");
        }
コード例 #5
0
        public void TestCaptureStateOfEnum_KindOf()
        {
            var objUnderTest = EnumType.Two;

            var stateVars = RollbarAssistant.CaptureState(objUnderTest, nameof(objUnderTest));

            Assert.IsNull(stateVars);

            stateVars = RollbarAssistant.CaptureState(typeof(EnumType));

            Assert.IsNull(stateVars);
        }
コード例 #6
0
        public void TestCombinedStateCapture()
        {
            var objUnderTest = new InstanceType();

            var combinedState = RollbarAssistant.CaptureState(objUnderTest, nameof(objUnderTest));

            RollbarAssistant.CaptureState(typeof(StaticType), combinedState);

            Assert.AreEqual(
                RollbarAssistant.CaptureState(objUnderTest, nameof(objUnderTest)).Count + RollbarAssistant.CaptureState(typeof(StaticType)).Count
                , combinedState.Count
                );
        }
コード例 #7
0
        public void TestCaptureStateOfObjectInstance()
        {
            var objUnderTest = new InstanceType();

            var stateVars = RollbarAssistant.CaptureState(objUnderTest, nameof(objUnderTest));

            Assert.AreEqual(2 + 4, stateVars.Count);

            foreach (var key in stateVars.Keys)
            {
                Console.WriteLine($"{key} = {stateVars[key]}");
            }
        }
コード例 #8
0
        public void TestCaptureStateOfInterface_KindOf()
        {
            var stateVars = RollbarAssistant.CaptureState(typeof(IInterface));

            Assert.IsNull(stateVars);
        }