添加 Swagger

dotnet add web-logger.csproj package Swashbuckle.AspNetCore -v 6.2.3

Program.cs

builder.Services.AddControllers();

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

https://localhost:<port>/swagger/index.html 添加一行 uniFormat 設置,讓專案除錯啟動的時候打開 swagger 讓Swagger 認得 IActionResult 的 api 接收/回傳型別 https://stackoverflow.com/questions/53105513/swagger-not-generating-model-for-object-wrapped-by-iactionresult

"serverReadyAction": {
    "action": "openExternally",
    "pattern": "^\\s*Now listening on:\\s+(https?://\\S+)",
    "uriFormat": "%s/swagger"
}

ASP.NET Core doesn’t include a logging provider for writing logs to files. To write logs to files from an ASP.NET Core app, consider using a third-party logging provider. https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-6.0 .NET Standard 2.0 之後內建沒有 ConfigurationManager ,需要額外安裝 dotnet add package System.Configuration.ConfigurationManager --version 6.0.0 https://stackoverflow.com/questions/46360716/cant-use-system-configuration-configuration-manager-in-a-net-standard2-0-libra

Reference

https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-6.0&tabs=visual-studio-code