# errorgap for .NET / ASP.NET Core

See [index.md](./index.md) for API details and the placeholder values (`ERRORGAP_API_KEY`, `ERRORGAP_ENDPOINT`, `ERRORGAP_PROJECT_SLUG`).

SDK source: `github.com/errorgaphq/errorgap-dotnet` · current version: `0.2.0`. Requires .NET 8+.

## Install

```sh
dotnet add package Errorgap.AspNetCore
```

For non-web apps depend on `Errorgap` directly.

## Configure (ASP.NET Core)

`Program.cs`:

```csharp
using Errorgap.AspNetCore;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddErrorgap(cfg =>
{
    cfg.Endpoint    = builder.Configuration["ERRORGAP_ENDPOINT"]!;
    cfg.ProjectSlug = builder.Configuration["ERRORGAP_PROJECT_SLUG"]!;
    cfg.ApiKey      = builder.Configuration["ERRORGAP_API_KEY"];
});

var app = builder.Build();
app.UseErrorgap();   // first, so it sees all downstream exceptions
app.MapGet("/", () => "ok");
app.Run();
```

The middleware reports thrown exceptions and re-throws so the framework's normal pipeline still handles the response.

## Configure (plain .NET)

```csharp
using Errorgap;

ErrorgapSdk.Init(new ErrorgapConfiguration
{
    Endpoint    = Environment.GetEnvironmentVariable("ERRORGAP_ENDPOINT")!,
    ProjectSlug = Environment.GetEnvironmentVariable("ERRORGAP_PROJECT_SLUG")!,
    ApiKey      = Environment.GetEnvironmentVariable("ERRORGAP_API_KEY"),
});
```

`Init` installs `AppDomain.UnhandledException` and `TaskScheduler.UnobservedTaskException` hooks.

## Trigger a test error

```csharp
app.MapGet("/errorgap-test", () => { throw new InvalidOperationException("Errorgap test error"); });
```

## Verify

Run the verification curl from [index.md](./index.md), then hit `/errorgap-test` and confirm the onboarding screen advances.
