.NET Core has considerably evolved since @Stefano’s answer a year ago. In .NET Core 2.0, you can now use the well-known AppDomain.CurrentDomain.ProcessExit
event instead of AssemblyLoadContext.Default.Unloading
. It works fine for console applications on Linux, also in Docker.