
Sponsor this newsletter to reach 10,000+ readers →
Tool of the Week: Seq
Seq is a structured logging and observability tool that works very well with .NET and Serilog.
Instead of digging through raw log files, you can search and filter logs by values like OrderId, UserId, status code, or exception type.
It also supports OpenTelemetry, so you can work with logs, traces, and metrics in one place.
Great for debugging production issues quickly.
Your API works perfectly on your machine.
The endpoints return the correct response, the database is connected, and Swagger looks good.
Then you deploy it.
An endpoint starts returning 500, but you have no useful logs. Your frontend gets blocked by CORS. A small response change breaks an older client. Six months later, you want to move files to another storage provider and discover that its SDK is used everywhere.
Most of these problems are easier to solve before production than after it.
Here are 8 things worth setting up early.
1. Add Logs, Metrics, and Traces
What problem does this solve?
Your API starts returning errors in production, but you have no idea where the problem is coming from.
A useful production setup normally gives you three kinds of information:
Logs tell you what happened.
Metrics tell you how the application is behaving over time.
Traces show what happened during a specific request.
.NET has ILogger built in, and you can use Serilog when you need structured logging and additional sinks.
For observability, OpenTelemetry supports logs, metrics, and distributed traces in .NET.
If you are using the Grafana stack, a common setup is:
Logs -> Loki
Metrics -> Prometheus
Traces -> Tempo
↓
GrafanaOne thing you should be very careful about is what you log.
Do not put passwords, access tokens, refresh tokens, API keys, authentication cookies, connection strings, card numbers, CVVs, or other sensitive user information in your logs.
ASP.NET Core’s HTTP logging documentation also warns that request and response logging can capture personally identifiable information and should be configured carefully.
A production error is already a problem.
You don’t want your logging system to become another one.
2. Don’t Expose Your API Documentation Publicly Unless You Need To
What problem does this solve?
Public API documentation gives anyone an easy map of your API.
They can see your endpoints, request models, parameters, and response contracts without doing much discovery themselves.
If the API is internal, there is usually no reason for its Swagger, Scalar, or OpenAPI endpoints to be publicly available.
For example:
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}This is also how Microsoft’s current ASP.NET Core OpenAPI examples expose the document only in development.
If you actually need documentation in production, protect it with authentication or put it behind something like Cloudflare Access.
One important distinction: API documentation itself does not bypass authorization or magically expose your production data.
The problem is unnecessary exposure of your API surface.
3. Configure CORS Properly
What problem does this solve?
Your frontend is deployed to another domain and suddenly every API request is blocked by the browser.
Or you solve that problem with:
.AllowAnyOrigin()and leave it there forever.
Instead, explicitly configure the frontend origins that should be allowed:
builder.Services.AddCors(options =>
{
options.AddPolicy("Frontend", policy =>
{
policy
.WithOrigins("https://app.example.com")
.AllowAnyHeader()
.AllowAnyMethod();
});
});Then:
app.UseCors("Frontend");CORS controls which browser origins are allowed to make cross-origin requests.
But CORS is not authentication.
It does not stop someone from calling your API through curl, Postman, another backend, or their own HTTP client.
Use CORS for browser-origin rules.
Use authentication and authorization to protect your API.
4. Think About API Versioning Before You Break a Client
What problem does this solve?
You publish this endpoint:
GET /api/ordersLater, you need to make a breaking change to its response.
Your web application may be easy to update, but what happens when an old mobile app or third-party integration still expects the previous contract?
That is where API versioning becomes useful:
GET /api/v1/orders
GET /api/v2/ordersASP.NET has a dedicated API Versioning project through the Asp.Versioning packages, including support for current .NET versions.
This does not mean every internal API needs /v1 on day one.
If the frontend and backend are always deployed together, versioning may only add unnecessary complexity.
But if you have mobile applications, external integrations, public APIs, or clients you cannot update immediately, decide your versioning strategy early.
Adding /v1 is easy.
Adding it after ten clients already depend on unversioned routes is not.
5. Don’t Couple File Storage to One Provider
What problem does this solve?
You start with one storage provider.
A year later, pricing changes, bandwidth becomes expensive, or another provider becomes a better fit.
Now you discover code like this all over the application:
await amazonS3.PutObjectAsync(...);Your application should not care whether the files are stored in AWS S3, Cloudflare R2, or somewhere else.
Put the storage implementation behind an abstraction:
public interface IFileStorage
{
Task UploadAsync(
string key,
Stream content,
CancellationToken cancellationToken);
Task<Stream> DownloadAsync(
string key,
CancellationToken cancellationToken);
}Then your application depends on IFileStorage, not a particular vendor SDK.
This becomes even easier when your providers support an S3-compatible API.
There is also one important update here if you were considering MinIO for a new project: the minio/minio GitHub repository was archived on April 25, 2026 and is now read-only.
The broader lesson still stands.
Design storage so replacing the provider is an infrastructure change, not an application rewrite.
6. Return a Consistent Error Format
What problem does this solve?
One endpoint returns:
{
"message": "User not found"
}Another returns:
{
"error": "USER_NOT_FOUND"
}And an unhandled exception returns something completely different.
Now every client has to handle errors differently.
ASP.NET Core already supports ProblemDetails, which gives HTTP APIs a consistent structure for error responses.
You can enable it with:
builder.Services.AddProblemDetails();
var app = builder.Build();
app.UseExceptionHandler();
app.UseStatusCodePages();A response can look like this:
{
"type": "https://example.com/problems/order-not-found",
"title": "Order not found",
"status": 404,
"detail": "Order 123 could not be found.",
"code": "ORDER_NOT_FOUND",
"traceId": "00-f83..."
}On the frontend, you can keep a predictable contract:
export interface ApiProblemDetails {
title?: string;
detail?: string;
status?: number;
type?: string;
code?: string;
traceId?: string;
}code gives the client something stable to react to.
traceId gives you something useful to search when the user reports a production problem.
You do not necessarily need to wrap every successful API response inside custom objects like:
{
"success": true,
"data": {}
}HTTP already gives you status codes for that.
The important part is making your error contract predictable.
7. Add Health Checks
What problem does this solve?
Your process is running.
That does not always mean your application is ready to receive traffic.
Maybe startup has not finished. Maybe an important dependency is unavailable. Maybe a new instance has started, but it is not ready yet.
ASP.NET Core has health checks built in:
builder.Services.AddHealthChecks();
var app = builder.Build();
app.MapHealthChecks("/health");A simple /health endpoint is enough for smaller applications.
For containerized applications, you can go further and separate readiness and liveness checks.
Liveness asks:
Is this application still alive?Readiness asks:
Should this application receive traffic right now?ASP.NET Core supports both patterns, and orchestrators or load balancers can use those results when deciding whether to route traffic or restart an instance.
Without health checks, your infrastructure may only discover a broken instance when your users do.
8. Add Rate Limiting Before One Client Uses Everything
What problem does this solve?
A frontend bug accidentally sends the same request hundreds of times.
A client starts polling an expensive endpoint continuously.
Or somebody intentionally sends more traffic than your API should accept.
Without limits, one consumer can use resources that should be available to everyone.
ASP.NET Core has built-in rate-limiting middleware.
For example:
builder.Services.AddRateLimiter(options =>
{
options.AddFixedWindowLimiter("api", limiter =>
{
limiter.PermitLimit = 100;
limiter.Window = TimeSpan.FromMinutes(1);
});
});Then apply it:
app.UseRateLimiter();
app.MapControllers()
.RequireRateLimiting("api");ASP.NET Core supports fixed-window, sliding-window, token-bucket, and concurrency limiters.
Do not randomly choose something like 100 requests/minute and assume you are finished.
An endpoint returning a cached object and an endpoint generating a report have completely different costs.
Choose limits based on the actual workload and load-test them.
Whenever you’re ready, there are 3 ways I can help you:
I work with founders and growing businesses to design, build, and improve reliable web apps. Let’s talk →
Promote yourself to 10,000+ subscribers by sponsoring this newsletter →
Boost your .NET skills by subscribing to my YouTube Channel →


