Managing exceptions

In this recipe, you will learn how to manage exceptions with Web API.

Usually, we don't want to lose the cause of an exception. So, we should persist and maintain all the exception's logs. Exception logs can be huge in terms of storage capacity needed to persist them.

We can log all the exceptions in files, or a database table (such as MSSQL, Oracle, or MySql), or document stores (such as MongoDb (https://www.mongodb.com/), or Azure CosmosDb (https://azure.microsoft.com/en-us/services/cosmos-db/)).

The logged exception would contain at least:

  • A descriptive message
  • The exception message
  • The exception .NET type
  • The stack trace

We generally send only the descriptive message to the client, and log other information about ...

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.