I have a multi-layered web application, layers are like below.
- MyApp.Models
- MyApp.Views
- MyApp.Controllers
- MyApp.Services
- MyApp.Repository.EF
In this architecture i have a seperated controllers class project as you may guess. Let's imagine that i want to add a category into db in this application.
For this transaction i follow these project steps below,
Controllers > Services > Repository > DB
For this transaction i follow these method steps in projects below,
CreateAction > CreateCategory > InsertEntity > CategoryTable
In all of those methods in layers, i use try-catch blocks for loging any exception occurs. I do wonder it is correct or not? I really bored to write try-catch blocks for loging things in every following steps for possible errors in every tier.
What is the best practice to log in multi-layered application like mine?
As a Java developer, I would create some new types of Exceptions (Runtime, Checked, etc.) with a constructor accepting other exceptions instances as parameters and/or other (business or technical) parameters. In this constructor I may log what I want. By this way, I will avoid all these try catch blocks done for logging.