public void Invoke(UnhandledExceptionEventHandler exceptionHandler) { try { _callback(_state); } catch (Exception ex) { exceptionHandler?.Invoke(this, new UnhandledExceptionEventArgs(ex, false)); } }
public void EndpointAddressFromConfigurationActiveIsUsedForSending() { UnhandledExceptionEventHandler handler = null; using (var module = new UnhandledExceptionTelemetryModule( h => handler = h, _ => { }, this.moduleChannel)) { handler.Invoke(null, new UnhandledExceptionEventArgs(null, true)); } Assert.Equal("http://test.com", this.moduleChannel.EndpointAddress); }
public void TrackedExceptionsHaveCorrectMessage() { UnhandledExceptionEventHandler handler = null; using (var module = new UnhandledExceptionTelemetryModule( h => handler = h, _ => { }, this.moduleChannel)) { handler.Invoke(null, new UnhandledExceptionEventArgs(new ApplicationException("Test"), true)); } Assert.Equal("Test", ((ExceptionTelemetry)this.items[0]).Exception.Message); }
public void TrackedExceptionsHavePrefixUsedForTelemetry() { UnhandledExceptionEventHandler handler = null; using (var module = new UnhandledExceptionTelemetryModule( h => handler = h, _ => { }, this.moduleChannel)) { handler.Invoke(null, new UnhandledExceptionEventArgs(null, true)); } Assert.True(this.items[0].Context.GetInternalContext().SdkVersion.StartsWith("unhnd: ", StringComparison.OrdinalIgnoreCase)); }
public void InstrumentationKeyCanBeOverridenInCodeAfterModuleIsCreated() { // This scenario is important for CloudApps where everything exept iKey comes from ai.config UnhandledExceptionEventHandler handler = null; using (var module = new UnhandledExceptionTelemetryModule( h => handler = h, _ => { }, this.moduleChannel)) { TelemetryConfiguration.Active.InstrumentationKey = "MyKey2"; handler.Invoke(null, new UnhandledExceptionEventArgs(null, true)); } Assert.Equal("MyKey2", this.items[0].Context.InstrumentationKey); }
public void TrackedExceptionsHavePrefixUsedForTelemetry() { string expectedVersion = SdkVersionHelper.GetExpectedSdkVersion(typeof(UnhandledExceptionTelemetryModule), prefix: "unhnd:"); UnhandledExceptionEventHandler handler = null; using (new UnhandledExceptionTelemetryModule( h => handler = h, _ => { }, this.moduleChannel)) { handler.Invoke(null, new UnhandledExceptionEventArgs(null, true)); } Assert.Equal(expectedVersion, this.items[0].Context.GetInternalContext().SdkVersion); }
public void FlushIsCalledToBeSureDataIsSent() { bool called = false; this.moduleChannel.OnFlush = () => called = true; UnhandledExceptionEventHandler handler = null; using (var module = new UnhandledExceptionTelemetryModule( h => handler = h, _ => { }, this.moduleChannel)) { handler.Invoke(null, new UnhandledExceptionEventArgs(null, true)); } Assert.True(called); }
public void TelemetryInitializersFromConfigurationActiveAreUsedForSending() { bool called = false; var telemetryInitializer = new StubTelemetryInitializer { OnInitialize = item => called = true }; TelemetryConfiguration.Active.TelemetryInitializers.Add(telemetryInitializer); UnhandledExceptionEventHandler handler = null; using (var module = new UnhandledExceptionTelemetryModule( h => handler = h, _ => { }, new InMemoryChannel())) { handler.Invoke(null, new UnhandledExceptionEventArgs(null, true)); } Assert.True(called); }
public Game1() { handler = new UnhandledExceptionEventHandler(Target); try { outWriter.WriteLine(DateTime.Now.ToLongDateString() + ", " + DateTime.Now.ToLongTimeString()); PrintToOutput("Starting Program"); graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; guiManager = new GuiManager(Services); inputManager = new InputManager(Services, Window.Handle); Components.Add(this.inputManager); Components.Add(this.guiManager); this.guiManager.DrawOrder = 1000; IsMouseVisible = true; PrintToOutput("Finished Starting Program"); } catch (Exception e) { handler.Invoke(e, new UnhandledExceptionEventArgs(e, true)); } }
private void OnUnhandledException(UnhandledExceptionEventArgs args) => unhandledException?.Invoke(this, args);