﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

namespace aspnet_start
{
    public class Startup
    {
        public static IWebHost WebHost = null;

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime lifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            lifetime.ApplicationStarted.Register(OnAppStarted);

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }

        private void OnAppStarted()
        {
            Program._startupTimer.Stop();
            Log($"Startup elapsed ms: {Program._startupTimer.ElapsedMilliseconds} ms");
            WebHost.StopAsync(TimeSpan.FromSeconds(1));
        }

        private void Log(string s)
        {
            string time = DateTime.UtcNow.ToString();
            Console.WriteLine($"[{time}] {s}");
        }
    }
}

﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

namespace aspnet_start
{
    public class Startup
    {
        public static IWebHost WebHost = null;

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime lifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            lifetime.ApplicationStarted.Register(OnAppStarted);

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }

        private void OnAppStarted()
        {
            Program._startupTimer.Stop();
            Log($"Startup elapsed ms: {Program._startupTimer.Elapsed.TotalMilliseconds} ms");
            WebHost.StopAsync(TimeSpan.FromSeconds(1));
        }

        private void Log(string s)
        {
            string time = DateTime.UtcNow.ToString();
            Console.WriteLine($"[{time}] {s}");
        }
    }
}

Add more precision to aspnet_start reported times.
Add more precision to aspnet_start reported times.
