dotnet-ops
Skill1 starsChanged 55 days agoMITView on GitHub
Production .NET operations advisor. Always use this skill when deploying or operating ASP.NET Core applications, configuring Kestrel, IHostedService, BackgroundService, health checks, graceful shutdown, SIGTERM, structured logging, or IOptions validation. Use when the user asks "graceful shutdown in ASP.NET Core", "BackgroundService exception handling", "IOptions eager validation", "health checks in .NET", "structured logging with Serilog", "SIGTERM in .NET", or "run background work in .NET". Read this skill before advising on any .NET production or deployment topic.
In this repository25 other files it gives its agents.
- api-designSkill
- arch-reviewSkill
- db-reviewSkill
- debugSkill
- dotnet-asyncSkill
- dotnet-testingSkill
- dotnet-typesSkill
- go-concurrencySkill
- go-opsSkill
- go-testingSkill
- go-typesSkill
- incidentSkill
- node-asyncSkill
- node-opsSkill
- perfSkill
- pr-prepSkill
- py-asyncSkill
- py-opsSkill
- py-testingSkill
- py-typesSkill
- refactorSkill
- securitySkill
- test-genSkill
- ts-testingSkill
- ts-typesSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 80
Don't read IConfiguration directly in services.
- Very specific: line 112
Use ILogger<T>; it's built in and integrates with any sink.
- Very specific: line 158
If ExecuteAsync throws, the host logs the exception but continues running: the background service stops silently.
- Very specific: line 173
Always set ASPNETCORE_ENVIRONMENT to Production in production: it disables developer exception pages and switches behavior in several …
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Production .NET Operations
ASP.NET Core is production-ready out of the box, but several defaults need explicit configuration before a service is truly operational: graceful shutdown, meaningful health checks, structured logging, and validated configuration. These aren't nice-to-haves; they're the difference between a service that degrades gracefully and one that drops requests during deploys.
Graceful shutdown
.NET's generic host handles SIGTERM and SIGINT automatically: it triggers IHostApplicationLifetime.ApplicationStopping and waits for hosted services to stop. Configure the timeout:
// Program.cs
builder.Services.Configure<HostOptions>(options =>
{
options.ShutdownTimeout = TimeSpan.FromSeconds(30);
});For Kestrel (HTTP), in-flight requests are drained during shutdown. To stop accepting new connections while draining:
var lifetime = app.Services.GetRequiredService<IHostApplicationLifetime>();
lifetime.ApplicationStopping.Register(() =>
{
// Signal readiness probe to return 503 — stops new traffic from routing here
_isShuttingDown = true;
});For custom resources (message consumers, database connections), implement IHostedService:
public class MyConsumer : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await foreach (var message in _queue.ReadAsync(stoppingToken))
{
await ProcessAsync(message, stoppingToken);
}
// Loop exits cleanly when stoppingToken is cancelled
}
}BackgroundService handles the hosted service lifecycle. Override ExecuteAsync and respect the stoppingToken.
Health checks
ASP.NET Core has built-in health check middleware. Separate liveness from readiness:
builder.Services.AddHealthChecks()
.AddCheck("live", () => HealthCheckResult.Healthy(), tags: ["live"])
.AddNpgsql(connectionString, tags: ["ready"]) // checks DB connectivity
.AddCheck<CustomReadinessCheck>("app-ready", tags: ["ready"]);
app.MapHealthChecks("/health/live", new HealthCheckOptions
{
Predicate = check => check.Tags.Contains("live"),
});
app.MapHealthChecks("/health/ready", new HealthCheckOptions
{
Predicate = check => check.Tags.Contains("ready"),
ResultStatusCodes = {
[HealthStatus.Healthy] = 200,
[HealthStatus.Degraded] = 200,
[HealthStatus.Unhealthy] = 503,
},
});The readiness check should fail during startup (before the app is configured) and during shutdown. Use IHostApplicationLifetime to flip a flag on shutdown and include it in the readiness check.
Configuration with IOptions
Don't read IConfiguration directly in services; bind it to typed options classes and inject those instead. This validates at startup, is testable, and is refactor-safe.
// Options class
public class EmailOptions
{
public const string Section = "Email";
[Required]
public string SmtpHost { get; init; } = default!;
[Range(1, 65535)]
public int SmtpPort { get; init; } = 587;
}
// Registration — ValidateDataAnnotations catches missing required config at startup
builder.Services.AddOptions<EmailOptions>()
.BindConfiguration(EmailOptions.Section)
.ValidateDataAnnotations()
.ValidateOnStart(); // fail at startup, not on first use
// Usage
public class EmailService(IOptions<EmailOptions> options)
{
private readonly EmailOptions _opts = options.Value;
}Environment variable overrides: .NET configuration providers stack in order. The ASPNETCORE_ and DOTNET_ prefixes are automatically mapped; for custom sections use double underscore for nesting: Email__SmtpHost=smtp.example.com.
Structured logging
Use ILogger<T>; it's built in and integrates with any sink. Add Serilog for production-quality structured output:
// Program.cs
builder.Host.UseSerilog((ctx, config) =>
{
config
.ReadFrom.Configuration(ctx.Configuration)
.Enrich.FromLogContext()
.WriteTo.Console(new JsonFormatter()); // JSON for log aggregators
});// In services — use source-generated logging for performance
public partial class UserService(ILogger<UserService> logger)
{
[LoggerMessage(Level = LogLevel.Information, Message = "User {UserId} created")]
private partial void LogUserCreated(string userId);
}Source-generated logging ([LoggerMessage]) avoids boxing and string allocation on the hot path; use it in high-throughput services.
Log levels: Error for actionable failures, Warning for degraded but functional, Information for significant lifecycle events, Debug for local dev only. Never Debug in production by default.
Background services
For recurring work, use BackgroundService:
public class CleanupJob : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
await DoCleanupAsync(stoppingToken);
await Task.Delay(TimeSpan.FromHours(1), stoppingToken);
}
}
}
builder.Services.AddHostedService<CleanupJob>();If ExecuteAsync throws, the host logs the exception but continues running: the background service stops silently. Handle exceptions inside ExecuteAsync or use IHostApplicationLifetime.StopApplication() to fail the whole process if the job is critical.
Kestrel in production
Behind a reverse proxy (nginx, YARP, Azure Front Door), Kestrel's defaults are fine. Direct internet exposure needs tuning:
builder.WebHost.ConfigureKestrel(options =>
{
options.Limits.MaxConcurrentConnections = 1000;
options.Limits.RequestHeadersTimeout = TimeSpan.FromSeconds(30);
options.Limits.MaxRequestBodySize = 10 * 1024 * 1024; // 10 MB
});Always set ASPNETCORE_ENVIRONMENT to Production in production: it disables developer exception pages and switches behavior in several middleware components.
What to watch for in code review
ShutdownTimeoutnot configured: process killed mid-request during deploys- A single
/healthendpoint serving both liveness and readiness purposes IConfiguration["Key"]read directly in services instead ofIOptions<T>ValidateOnStart()missing: config errors surface at runtime, not startupBackgroundService.ExecuteAsyncwithout exception handling: job fails silentlyConsole.WriteLineorDebug.WriteLineinstead ofILoggerASPNETCORE_ENVIRONMENTnot set: app runs in Development mode in production
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

