I have this in my Startup.cs:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Microsoft.Extensions.Hosting.IApplicationLifetime appLifetime)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
appLifetime.ApplicationStopping.Register(() => Console.WriteLine("ApplicationStopping called"));
appLifetime.ApplicationStopped.Register(() => Console.WriteLine("ApplicationStopped called"));
}
I start my dotnet app: dotnet run --project myapp/myapp.csproj
.
I get the process ID: ps | grep "dotnet run --project myapp/myapp.csproj"
I send the process a sigterm: kill <PID>
.
The app terminates immediately and I don't see my console log messages. kill is supposed to send a SIGTERM by default.
Am I using IApplicationLifetime wrong or am I sending the SIGTERM wrong?
Edit
I think I might be using IApplicationLifetime wrong because I added this as well and I never see these messages either:
appLifetime.ApplicationStarted.Register(() => Console.WriteLine("ApplicationStarted called"));