Specifically what I am doing is in my AppServiceProvider->boot() method I am creating a singleton class like below:
class AppServiceProvider extends ServiceProvi
IMHO you can try to add a terminating callback to your app instance, for example in the AppServiceProvider, i.e.:
AppServiceProvider
public function boot() { $this->app->terminating(function () { // your terminating code here }); }