After a lot of trial and error, In order to find the cause, I have reduced the startup to this:
public class Startup
{
public void Configuration(IAppBuilder app)
{
RegisterOnShutdown(app);
Log.Debug("\n Startup end !!!");
}
private void RegisterOnShutdown(IAppBuilder app)
{
var context = new OwinContext(app.Properties);
var token = context.Get<CancellationToken>("host.OnAppDisposing");
if (token != CancellationToken.None)
{
token.Register(OnShutdown);
}
}
private void OnShutdown()
{
Log.Debug("\n Shutdown !!!");
}
}
And I get this log:
2022-12-11 08:00:27,045 [1] DEBUG (null) Web.Startup [(null)] <(null)> -
Startup end !!!
2022-12-11 08:00:29,751 [7] DEBUG (null) Web.Startup [(null)] <(null)> -
Shutdown !!!
Why is this happening?
The log file was put in the bin folder, which shouldn't have been, as it changes and causes change to the folder. Refer to this
Relocating the file solved the problem.