private static void OnExit(object sender, EventArgs e) { if (Interlocked.Exchange(ref _isExiting, value: 1) != 0) { // OnExit() was already called before return; } try { _tracerProvider?.Dispose(); _meterProvider?.Dispose(); _sdkEventListener.Dispose(); Logger.Information("OpenTelemetry Automatic Instrumentation exit."); } catch (Exception ex) { try { Logger.Error(ex, "An error occured while attempting to exit."); } catch { // If we encounter an error while logging there is nothing else we can do // with the exception. } } }