Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pakrym/321de275fafbdfdedefe9441e4acd983 to your computer and use it in GitHub Desktop.
Save pakrym/321de275fafbdfdedefe9441e4acd983 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
namespace WebApplication2
{
public class Program : IObserver<DiagnosticListener>, IObserver<KeyValuePair<string, object>>
{
public static void Main(string[] args)
{
new Program().MainImpl(args);
}
public void MainImpl(string[] args)
{
DiagnosticListener.AllListeners.Subscribe(this);
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Start();
new HttpClient().GetAsync("http://localhost:5000//")
.ContinueWith(task =>
{
Console.WriteLine("Request done");
})
.GetAwaiter().GetResult();
Console.WriteLine("Before Dispose");
host.Dispose();
Console.WriteLine("After Dispose");
Console.ReadLine();
}
public void OnCompleted()
{
}
public void OnError(Exception error)
{
}
public void OnNext(KeyValuePair<string, object> value)
{
Console.WriteLine(value.Key);
if (value.Key == "Microsoft.AspNetCore.Hosting.HttpRequestIn.Stop")
{
Thread.Sleep(3000);
Console.WriteLine("After Microsoft.AspNetCore.Hosting.HttpRequestIn.Stop");
}
}
public void OnNext(DiagnosticListener value)
{
value.Subscribe(this);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment