How would you resolve once and be able to access your logger across your application?

StackOverflow https://stackoverflow.com/questions/13593700

  •  02-12-2021
  •  | 
  •  

Вопрос

Using castle windsor and the LoggingFacility, how would you resolve once and be able to use your logger across your application? I understand that bootstrapping/installing is done in global.asax and that is where the resolve should be done but I am confused about how you would access your logger outside of global.asax.

Это было полезно?

Решение

The purpose of using Castle Windsor is to follow the Inversion of Control pattern, whereby you allow the container to inject dependencies (like the ILogger) into classes that require them. You "access the logger" by having your controllers (or whatever classes need to do logging) depend on ILogger, either by taking it as a constructor parameter, or by exposing a settable property of type ILogger.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top