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. ...
Fixes stale IntelliSense from Visual Studio's undocumented local JSON Schema cache: since the cache folder location isn't published, the workaround is Tools > Options > Text Editor > JSON > Schema, removing and re-adding the schemastore.org URL entry to force a refetch after reopening the file. ...
Walks through the System.InvalidOperationException thrown when a TimingMiddleware class tries to set an X-Took response header after calling await _next(context), then fixes it by moving the header assignment into context.Response.OnStarting, which runs just before headers are sent. ...