.NET Error Tracking installation
- 1
Install the .NET SDK
RequiredFor ASP.NET Core projects, install the PostHog.AspNetCore package:
TerminalFor other .NET projects, such as console applications, MAUI, or Blazor, install the core
PostHogpackage:Terminal - 2
Configure PostHog
RequiredFor ASP.NET Core, add PostHog to your
Program.csfile:C#Configure your project token and host in
appsettings.json:JSONFor non-ASP.NET Core projects, initialize the core client as a singleton:
C#You can find your project token and instance address in the project settings page in PostHog.
- 3
Capture exceptions
RequiredThe .NET SDK supports manual exception capture with
CaptureException. It builds the$exceptionevent for you, including exception type, message, stack frames, inner exceptions, aggregate exceptions, source context when available, and .NET runtime metadata.The examples below assume
posthogis anIPostHogClientfrom dependency injection, or your singletonPostHogClient.C#Pass additional properties to add request, tenant, or domain context to the exception:
C#You can also attach feature flag values to the exception event with a feature flag snapshot:
C#Automatic captureAutomatic exception capture is not available in the .NET SDK yet. Wrap the code paths you want to monitor and call
CaptureExceptionfrom your exception handlers. - 4
Capture ASP.NET Core request exceptions
RecommendedFor ASP.NET Core apps, add middleware to capture unhandled request exceptions and then rethrow them so your existing error handling still runs:
C# Verify error tracking
RecommendedTrigger and capture a test exception to confirm events are being sent to PostHog. You should see it appear in the Error Tracking tab.
C#For serverless environments, call
FlushAsync()before the process exits so queued exception events are sent.