From the course: ASP.NET Core: Health Checks and Logging

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Add logging to the sample app

Solution: Add logging to the sample app - ASP.NET Core Tutorial

From the course: ASP.NET Core: Health Checks and Logging

Start my 1-month free trial

Solution: Add logging to the sample app

(upbeat music) - [Instructor] Since we've shut down the database anyway, let's start with logging the exception. So, I hit F5 to start this in debug mode. The API is launching, and so far so good, however, when I try out a call to the API, well, the code tries to connect to the database, but no avail, and after a while, well, basically we give up or that gives up because the timeout is reached and then we get the exception. So, we get the exception here in the constructor. So, we could try to log with the constructor. What we could also do is we could go to programs. Yes, and in the main method, just globally lock all exceptions. However, since I was specifically asking for the database and the database has only been used here, we can try something like this. So, we do a try and then catch an exception and make sure, that you're first set, logger, and then the database context. And then we could do a…

Contents