Skip to main content

Introduction

Lerix.AspNetCore is the server-side Lerix SDK for ASP.NET Core. After two lines in Program.cs, every unhandled exception in your API is reported to the dashboard with its stack trace, host, release and request context, and your services get a typed client for the push notifications REST API.
Create a project with the ASP.NET framework in the dashboard and copy its API key and project id from Project Settings.

Requirements

The Lerix core package also targets .NET Standard 2.0 for console apps, workers and functions that do not use ASP.NET Core.

1. Install the package

2. Register the SDK

Add the services and the middleware in Program.cs:
Program.cs
Put the options in appsettings.json or, for the secrets, in user secrets or environment variables:
appsettings.json
ApiKey and ProjectId also fall back to the LERIX_API_KEY and LERIX_PROJECT_ID environment variables, so the section can be omitted entirely on a server that already sets them. That is the whole setup. AddLerix registers a hosted service that connects to your project on startup and flushes pending reports on shutdown, and UseLerix adds the middleware that reports unhandled exceptions. See Error Tracking for what gets captured and how to report errors yourself.
Call app.UseLerix() after UseExceptionHandler or UseDeveloperExceptionPage and before routing and endpoints. Those handlers catch exceptions from the middleware that follows them, so if Lerix is registered earlier it never sees the exception.

Configure in code

AddLerix also accepts a delegate, alone or on top of a configuration section:
Program.cs

3. Verify the integration

Add an endpoint that throws and call it once:
Program.cs
The client receives your app’s normal 500 response and the error appears in your dashboard within seconds. Remove the endpoint afterwards.

Options

Every option is a property of LerixAspNetCoreOptions, settable from configuration or the delegate.

How your service appears in the dashboard

The SDK registers your service as a server app. The app id defaults to the entry assembly name and the release to its informational version (the <Version> in your .csproj), so reports are grouped per service and per release. Override them with App when you deploy several instances of the same code base or want a git SHA as the build number:
Program.cs
An anonymous user is registered on first boot and stored in .lerix/state.json under the working directory, so restarts reuse it. Add that folder to .gitignore, or mount it in containers. Set PersistState = false to skip persistence, or UserId to control the id yourself.

Outside ASP.NET Core

Console apps, workers and functions can use the Lerix package directly:

Next steps

Error Tracking

What the middleware reports, how to change the policy, and manual reporting.

Push Notifications

Send, schedule, update and unsend notifications from your backend.