Skip to content

Instantly share code, notes, and snippets.

@MatthewDavidCampbell
Created February 8, 2018 12:00
Show Gist options
  • Save MatthewDavidCampbell/e32219295786efef8dfcebcf3a71783f to your computer and use it in GitHub Desktop.
Save MatthewDavidCampbell/e32219295786efef8dfcebcf3a71783f to your computer and use it in GitHub Desktop.
HealthCheck netstandard2.0
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
<PackageReference Include="Microsoft.AspNetCore.HealthChecks" Version="1.0.0-alpha-4" />
</ItemGroup>
</Project>
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace HealthEndpoint
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseHealthChecks("/hc")
.UseStartup<Startup>()
.Build();
}
}
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.HealthChecks;
namespace HealthEndpoint
{
public class Startup
{
// 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)
{
services.AddMvc();
services.AddHealthChecks(checks => {
checks.AddValueTaskCheck(
"HTTP Endpoint",
() => new ValueTask<IHealthCheckResult>(HealthCheckResult.Healthy("Ok")));
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment