{"id":17676456,"url":"https://github.com/trossr32/net-core-console-app-template","last_synced_at":"2026-04-24T21:31:45.721Z","repository":{"id":115141334,"uuid":"284969251","full_name":"trossr32/net-core-console-app-template","owner":"trossr32","description":"An empty net core console app with command line arg options, DI, SeriLog logging \u0026 json config","archived":false,"fork":false,"pushed_at":"2025-08-14T21:52:40.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-14T23:26:49.806Z","etag":null,"topics":["dotnet","dotnet-core","dotnet7","net7"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trossr32.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-04T12:14:37.000Z","updated_at":"2025-08-14T21:52:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"ed7e3b5f-b71b-47e4-974c-694b55576246","html_url":"https://github.com/trossr32/net-core-console-app-template","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/trossr32/net-core-console-app-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trossr32%2Fnet-core-console-app-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trossr32%2Fnet-core-console-app-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trossr32%2Fnet-core-console-app-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trossr32%2Fnet-core-console-app-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trossr32","download_url":"https://codeload.github.com/trossr32/net-core-console-app-template/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trossr32%2Fnet-core-console-app-template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32241591,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotnet","dotnet-core","dotnet7","net7"],"created_at":"2024-10-24T07:25:39.623Z","updated_at":"2026-04-24T21:31:45.716Z","avatar_url":"https://github.com/trossr32.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# .NET 10 Console App Template\n\nMinimal, opinionated .NET 10 console template with:\n\n* Dependency Injection (Microsoft.Extensions)\n* Command line parsing (`System.CommandLine`)\n* Structured logging (Serilog)\n* Graceful Ctrl+C cancellation\n* Separation of concerns via Core / Services / Console projects\n* Central Package Management (Directory.Packages.props)\n\n## Project Structure\n\n* `App.Console` – Entry point, command + option wiring, DI + cancellation setup.\n* `App.Core` – Cross‑project models (e.g. `RunModel`).\n* `App.Services` – Business/service layer (`ProcessService`).\n\n## Key Components\n\n### Program (`App.Console/Program.cs`)\nSets up configuration, Serilog console logger, registers services, builds a `RootCommand` named `app`, wires Ctrl+C to cancellation, and invokes it with a `CancellationToken`.\n\n### Command Extension (`RunRootCommand`)\nAdds the run behavior to the root command:\n* Registers option `--test` / `-t` (boolean, optional).\n* Binds parsed values into `RunModel`.\n* Executes `ProcessService.Process`.\n\n### Model (`RunModel`)\n```csharp\npublic class RunModel { public bool Test { get; set; } }\n```\nRepresents command input passed to services.\n\n### Service (`ProcessService`)\nLogs either \"Testing!\" when `--test` is supplied or \"Running!\" otherwise.\n\n## Features\n\n* Clean separation between parsing, orchestration, and execution.\n* Graceful shutdown on Ctrl+C (SIGINT) using `CancellationTokenSource` and `Console.CancelKeyPress`.\n* Simple extension model: add new commands via extension classes similar to `RunRootCommand`.\n* DI ready: register more services in `Program.cs`.\n* Serilog output template kept minimal: `{Message}{NewLine}{Exception}`.\n\n## Prerequisites\n\n* .NET 10 SDK (C# 14). Adjust target framework if using a different SDK.\n\n## Getting Started\n\n1. Clone repository.\n2. Restore packages: `dotnet restore`.\n3. Build: `dotnet build`.\n4. Run:\n   * Default: `dotnet run --project App.Console`\n   * Test mode: `dotnet run --project App.Console -- --test`\n   * Short alias: `dotnet run --project App.Console -- -t`\n\nNote the `--` separator before command options when using `dotnet run`.\n\n## Command Reference\n\nRoot command name: `app`\n\nOptions:\n* `--test | -t` – Simulates a test run (logs \"Testing!\").\n\nExit codes:\n* `0` – Success.\n* Non‑zero – Unhandled exception (logged as error).\n* Cancelled – Returns success after logging \"Operation cancelled.\" (no stack trace).\n\n## Ctrl+C Cancellation\n\nPressing Ctrl+C sends SIGINT. The template:\n* Intercepts the event (`Console.CancelKeyPress`).\n* Prevents immediate termination (`eventArgs.Cancel = true`).\n* Signals a `CancellationTokenSource`.\n* Logs a friendly shutdown message.\n* Catches `OperationCanceledException` and logs \"Operation cancelled.\" before flushing logs.\n\nExtend services/commands to honour the token by passing it into async operations.\n\n## Logging\n\nConfigured to write to console only. Modify `Program.cs` to add sinks (e.g. file, Seq):\n```csharp\nLog.Logger = new LoggerConfiguration()\n    .WriteTo.Console()\n    //.WriteTo.File(\"logs/log.txt\")\n    .CreateLogger();\n```\n\n## Error Handling\n\nExceptions inside the run pipeline are caught, logged with `logger.LogError`, and rethrown (allowing process exit with failure code for shell scripting). Cancellation is treated as a graceful path.\n\n## License\n\nUse/modify freely.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrossr32%2Fnet-core-console-app-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrossr32%2Fnet-core-console-app-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrossr32%2Fnet-core-console-app-template/lists"}