Shows how to unit test a Jokes class that calls the JokeAPI through HttpClient with NUnit, by implementing a custom HttpMessageHandler to intercept requests instead of hitting the real https://v2.jokeapi.dev/joke/Programming endpoint, avoiding flaky integration-test failures when the API is down. ...
Explains setting up correlation IDs across ASP.NET Core services with the Elmah.Io.AspNetCore and Elmah.Io.Extensions.Logging packages, configured via AddElmahIo and UseElmahIo in Program.cs, so a request, its NullReferenceException, and related ILogger messages group into one elmah.io view. ...
Shows how to unit test logging calls in a Math.Divide method using the FakeLogger<T> class from the Microsoft.Extensions.Diagnostics.Testing NuGet package, asserting on logger.Collector.LatestRecord.Message and Collector.Count with NUnit rather than only relying on NullLogger. ...
Explains how to install the Elmah.Io.Client.Extensions.SourceCode NuGet package, set EmbedAllSources true in the .csproj, and call msg.WithSourceCodeFromPdb() inside the AddElmahIo OnMessage callback so elmah.io shows the exact source line from a stack trace without cloning the repo. ...
Uses a joke NuGet package called RickrollingMiddleware to show how dotnet-validate (installed via dotnet tool install) catches failing Source Link, Deterministic, and Compiler Flags checks in GitHub Actions, then fixes them by adding DebugType embedded and PublishRepositoryUrl to the .csproj. ...
Demonstrates ASP.NET Core 8's AddKeyedSingleton and FromKeyedServices attribute by injecting two named ServiceBusSender clients, taskTopic and preprocessorTopic, from Azure.Messaging.ServiceBus into a controller, replacing a hand-written Topics wrapper class used to work around the ambiguity. ...
Provides copy-paste PowerShell code using the Test-Json cmdlet against a schema.json file to validate JSON syntax and structure in an Azure DevOps build, covering both the classic-editor PowerShell Script task and a YAML PowerShell@2 pipeline step, plus the pwsh: true fix needed on windows-latest. ...
Shows how to replace host.json's Application-Insights-only logging in in-process Azure Functions by installing Microsoft.Azure.Functions.Extensions, adding a FunctionsStartup-based Startup.cs, and calling AddLogging with Microsoft.Extensions.Logging.Console for full ILoggingBuilder control. ...
Extends a TimingMiddleware class that sets an X-Took response header, comparing an in-class StartsWithSegments("/api") if-check, which still runs the middleware for every request, against wrapping app.UseWhen in Program.cs so the pipeline branch only executes for matching paths. ...