How to log an error through out full application

I want to print a log whenever an exception is thrown by try-catch block through out whole application.

Global.asax is your friend here for all things except .NET Core, it has an Application_Error event and MVC also has an OnException event.

.NET Core requires you to do things a bit differently with an ExceptionFilterAttribute.

You can read more about these at

I thought I replied to this but I guess not.

As written, my assumption is that you are asking if it is appropriate to do what you are saying and my response is that you can do what you want.

If you are not asking for permission to do that then this is quite vague. I think that a single try-catch block will not be enough for the whole web application but we don’t know if you are asking about a desktop or web application. A single try-catch block might help for a console, Windows Forms or WPF application.

The question is asking about try-catch blocks (actually just one for the entire application) explicitly. The title just says through out full application so there is an implied inconsistency there.

Exactly, on every try/catch block, you would simply put throw in the catch and let the global.asax catch it to log it.

You could in theory log it at each one, but I’d highly recommend against that. The whole point of try/catch blocks are for when you can handle the exception, if you can’t then don’t use a try/catch, just let the error bubble up on its own.