Let's say there is an application. For example asp.net mvc. It requires logging of certain operations and exceptions. Where is the most appropriate place to write to the log? Suppose our application has action controllers. Inside them are called certain services. The services contain business logic that does something and also communicates with the repository, which in turn works with the database. Something like this:
// action в контроллере public ActionResult SomeAction() { _myService.DoSomething(); } // метод в сервисе public void DoSomething() { // тут какая-то бизнес-логика, // например, мы что-то делаем с репозиторием _repository.DoSomethingMore(); // что-то еще } // метод в репозитории public void DoSomethingMore() { // здесь мы что-то делаем с базой using(var context = new Context()) { // вот тут происходит исключение // которое надо залогировать } } Logging is performed by static methods of a certain class of Log :
Log.Error(exception); The question is where to perform logging? In the repository? It is unlikely that he should know anything about it at all. In the service? It seems to me that it is a bad idea to associate business logic with a static logger class and make dependencies that way. In the controller? Or somewhere else? Please tell me how to do such things right?