We have been using the ILogger interface provided by .NET Core, but do you know how to leverage BeginScope for our benefit? Let’s explore how BeginScope helps us harness log scoping effectively. Let’s examine a sample transaction API in a minimal API project and see how one would typically write logs as the transaction flows…
When to Use SingleOrDefault vs FirstOrDefault? Many developers are familiar with the FirstOrDefault() method in LINQ for C#. However, there’s also SingleOrDefault(). What’s the key difference between them? And why might you choose one over the other instead of always sticking with FirstOrDefault()? Both methods work on collections that implement the IEnumerable<T> interface, allowing you…
If you’re working with just a single project in your solution, this article might not apply to youโfeel free to skip it. Thanks for stopping by! Why Do You Need Directory.Packages.props? Imagine you’re building a large .NET solution with dozens of projects: web APIs, class libraries, worker services, and more. Updating a shared NuGet packageโlike…
Letโs say you have a utility function thatโs used by multiple other functions to โdo the thing,โ and you want to log or print which function actually called this utility. How would you do that? For example, consider a function that extracts the user ID from a JWT token: Now, we want to log who…