Contact.WebApplication
1.0.1
dotnet add package Contact.WebApplication --version 1.0.1
NuGet\Install-Package Contact.WebApplication -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Contact.WebApplication" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Contact.WebApplication" Version="1.0.1" />
<PackageReference Include="Contact.WebApplication" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Contact.WebApplication --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Contact.WebApplication, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Contact.WebApplication@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Contact.WebApplication&version=1.0.1
#tool nuget:?package=Contact.WebApplication&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Contact.WebApplication
Contact.WebApplication is a .NET 8+ observability extension library for ASP.NET Core applications.
It provides opinionated, production-ready defaults for:
- Structured logging (Serilog)
- Distributed tracing (OpenTelemetry)
- Metrics & Prometheus scraping
- HTTP request/response logging with PII masking
- Environment-based enable/disable
- Feature-flag�ready configuration
Designed to be plugged into Minimal APIs and MVC apps with minimal friction.
Why This Library Exists
Modern applications require deep visibility into:
- What happened
- Where it happened
- Why it happened
Most teams wire logging, metrics, and tracing manually in every project�leading to:
- Inconsistent setups
- Copy-paste configurations
- Missing telemetry in production
Contact.WebApplication standardizes observability across services with a single extension call.
Features
- Centralized Observability Setup
- Serilog + OpenTelemetry + Prometheus
- HTTP Request & Response Logging
- Status codes
- Latency
- Headers (with PII masking)
- Tracing
- ASP.NET Core
- HTTP client calls
- Metrics
- Request duration
- Active requests
- Process metrics
- Environment-based Controls
- Enable/disable logs per environment
- Feature-Flag Friendly
- Safe rollout support
Installation
dotnet add package Contact.WebApplication
## Why This Library Was Created
In modern web applications, managing errors gracefully is essential for both debugging and providing a good user experience. The typical approach to exception handling involves wrapping each endpoint or request handler in a `try-catch` block, which can be cumbersome and repetitive.
The idea behind `Contact.WebApplication` is to centralize exception handling in a single middleware, so that all exceptions�regardless of where they occur�are caught and handled in one place. This simplifies the code, reduces redundancy, and ensures consistent error responses for all unhandled exceptions.
## How It Works
This library adds middleware to your `WebApplication` pipeline that intercepts all requests. When an unhandled exception occurs, the middleware catches it and returns a formatted JSON response with the exception details.
By using this middleware, you ensure that your application always returns a consistent error format, no matter where the exception originates.
## Features
- **Centralized Error Handling**: Catch all exceptions in one `try-catch` block.
- **JSON Response**: Automatically formats error messages in a JSON response.
- **Minimal Configuration**: Simple and straightforward integration into your application.
## Installation
You can add the `Contact.WebApplication` library to your .NET 8+ class library by referencing the project or package. Ensure that your project targets .NET 8+.
## Usage
### Step 1: Install the Library
Add `Contact.WebApplication` to your project by adding the necessary reference in your `.csproj` file or by using a package manager.
### Step 2: Use the Middleware
In your `Program.cs` or `Startup.cs` file, call the `UseGlobalExceptionHandler` extension method to add the middleware to the pipeline.
```csharp
using Contact.WebApplication;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container
....
builder.Services.AddContactObservability();
....
var app = builder.Build();
// Add global exception handler middleware
// was ##Deprecated## app.UseGlobalExceptionHandler();
app.UseContactObservability();
...
app.Run();
add appsettings.json configuration
"OpenTelemetryConfig": {
"ServiceName": "ServiceName",
"Meter": "ServiceName_otlp",
"OtlpExporterUrl": "http://host:9090/api/v1/otlp/v1/metrics",
"MetricsExportIntervalMs": 100000
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- OpenTelemetry (>= 1.14.0)
- OpenTelemetry.Api (>= 1.14.0)
- OpenTelemetry.Exporter.Console (>= 1.14.0)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.14.0)
- OpenTelemetry.Exporter.Prometheus.AspNetCore (>= 1.14.0-beta.1)
- OpenTelemetry.Extensions.Hosting (>= 1.14.0)
- OpenTelemetry.Instrumentation.AspNetCore (>= 1.14.0)
- OpenTelemetry.Instrumentation.Http (>= 1.14.0)
- OpenTelemetry.Instrumentation.Process (>= 1.14.0-beta.2)
- Serilog (>= 4.3.0)
- Serilog.AspNetCore (>= 10.0.0)
- Serilog.Enrichers.Environment (>= 3.0.1)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Sinks.Console (>= 6.1.1)
- Serilog.Sinks.File (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.