12 Troubleshooting your application

 

This chapter covers

  • Understanding the nature of an exception
  • Using StatusCodePages middleware to control the display of client error messages
  • Implementing logging within a Razor Pages application

By now, you’ve probably written a fair amount of code as you have worked your way through the chapters. Chances are you have encountered an error or two while doing so. Some of these will be compile-time errors your development tool will have caught, so you can fix them as you work. Others will have surfaced only at run time, raising exceptions that result in an error page of some kind being displayed. As you build more complex applications, other types of errors creep in: logical errors. These kinds of errors won’t stop your application from running, but they will result in unpredictable behavior. Coding errors, whether they are simply typos or logical errors, are a fact of a developer’s life.

12.1 Exception management

12.1.1 The Developer Exception page

12.1.2 ExceptionHandlerMiddleware

12.2 StatusCodePages

12.2.1 Exploring WithRedirects

12.2.2 StatusCodePages WithReExecute

12.3 Logging

12.3.1 Logging basics

12.3.2 Log levels

12.3.3 Log categories

12.3.4 Using EventIds

12.3.5 Formatting the log message

12.3.6 Applying log filter rules

12.3.7 Custom email logger