Tuesday Reading List

Inventory Dashboards Using the Power of Azure Resource Graph

Ever wonder what are all the resources in your Azure environment? You can now use power of Azure Resource Graph to query all the resources (or filter based on certain criteria).


Capture Web Application Logs with App Service Diagnostics Logging

Ever confused what logs are available in Azure? Well, I’m too. Specfically for Azure App Service however, the learning module helps you understand what’s your options.


Improve the developer experience of an API with Swagger documentation

Use Swagger in your next API project and you won’t have to hand-written those documentations. Heck, even use it in your existing API projects! This learning module will teach you how to implement Swagger in your ASP.NET Core API


10 GREAT .NET CORE 3.0 ARTICLES YOU MUST HAVE A LOOK

Never get enough of .NET Core 3.0? Well, these 10 articles should give you enough read for the week. From performance, migration to configuration, it covers lots of stuff you want to know about .NET Core 3.0.


The ultimate (free) CI/CD for your open-source projects

You probably already know, but maintaining open source project is difficult and take a lot of your time. So, if you could automate your CI/CD and it’s free? Sure, why not.


Sunday Reading List

gRPC + ASP.NET Core as a Migration Path for WCFs in .NET Core

It was fun while it lasts, now with .NET Core development ramping up, WCF and its services library have slowly become technical debt. This articles a guideline to migrate to ASP.NET Web API and gRPC..


System memory health check for ASP.NET Core

If you’re already deploying your application to Azure App Services, you’re familiar with memory health check that comes with it for free. But, let’s say for some reason you need to deploy to other services, like containers or VMs, this article will walk through how to implement memory health check in ASP.NET Core application.


Logging in C# .NET Modern-day Practices: The Complete Guide

A truly complete and comprehensive guide to logging in C# / .NET. Michael walks us through from target types, structured logging, frameworks and best practices around logging. The three frameworks discussed are: Serilog, NLog and log4net. I’m glad I’m not the only one thinking we have too many loggin options in .NET!


Developers: This cute 8-bit RPG game wants to teach you new coding skills

What’s the best way to teach developer your API? Create a game, of course! Twilio does just that. It’s pretty good game too!


What exactly is Kubernetes?

For Container / Kubernetes beginner, this is a really good article to get your started. It covers the basic of Kubernetes, all different parts of Kubernetes, what Kubernetes is NOT and how it actually works.


How to Implement IExceptionLogger and IExceptionHandler in Web Api .Net

This works on Web Api 2+ and MVC 5+.

1. Create implementation of ExceptionHandler class. Note this class inherit from concrete class of ExceptionHandler, not the interface. Inherit from concrete class decrease effort to implement other methods.

using System.Threading;
using System.Threading.Tasks;
using System.Web.Http.ExceptionHandling;

namespace BlahBlahBlah.ExceptionHandler
{
    public class GlobalExceptionHandler : System.Web.Http.ExceptionHandling.ExceptionHandler
    {
        public override Task HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken)
        {
            // Code to handle exception...

            return base.HandleAsync(context, cancellationToken);
        }
    }
}

2. Create implementation of ExceptionLogger class. Note this class inherit from concrete class of ExceptionLogger, not the interface. Inherit from concrete class decrease effort to implement other methods.

using System.Threading;
using System.Threading.Tasks;

namespace BlahBlahBlah.ExceptionHandler
{
    public class GlobalExceptionLogger : System.Web.Http.ExceptionHandling.ExceptionLogger
    {
        public override Task LogAsync(System.Web.Http.ExceptionHandling.ExceptionLoggerContext context, CancellationToken cancellationToken)
        {
            // Code to log exception...

            return base.LogAsync(context, cancellationToken);
        }
    }
}

3. Replace default Logger and Handler.

using System.Web.Http;
using System.Web.Http.ExceptionHandling;
using BlahBlahBlah.ExceptionHandler;

namespace BlahBlahBlah
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {            
            // Replace default exception handler and logger
            config.Services.Replace(typeof(IExceptionLogger), new GlobalExceptionLogger());
            config.Services.Replace(typeof(IExceptionHandler), new GlobalExceptionHandler());

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }
}

If you wonder difference between IExceptionLogger and IExceptionHandler, this is from Microsoft docs:

We provide two new user-replaceable services, IExceptionLogger and IExceptionHandler, to log and handle unhandled exceptions. The services are very similar, with two main differences:

1. We support registering multiple exception loggers but only a single exception handler.
2. Exception loggers always get called, even if we’re about to abort the connection. Exception handlers only get called when we’re still able to choose which response message to send.

Both services provide access to an exception context containing relevant information from the point where the exception was detected, particularly the HttpRequestMessage, the HttpRequestContext, the thrown exception and the exception source (details below).