Logging in DD4T

When you write a .NET web application based on DD4T, you will probably have some preferred way of logging. In most cases you would use one of the common logging frameworks, like Log4Net or MS EntLib. But how can you get DD4T itself to log?

DD4T does not confine you to one particular logging framework. Instead it has a wrapper architecture that makes it easy to support multiple types of logger. At the moment, MS EntLib and Log4Net are both supported. If you want to use a different logging framework you can easily write your own wrapper by copying one of the existing ones.

So how do you get logging to work?

  1. Add a reference to the logging framework of your choice (e.g. for MS EntLib that would be Microsoft.Practices.EnterpriseLibrary.Logging.dll).
  2. Configure this logging framework in the normal way.
  3. Add a reference to the corresponding DD4T log wrapper (in this case DD4T.LogWrappers.Entlib.dll).
  4. Add a key to the appSettings section of your Web.config to tell DD4T which log wrapper it should use:

<add key=”DD4T.LoggerClass” value=”DD4T.LogWrappers.Entlib.EntLibLogger, DD4T.LogWrappers.Entlib” />

That’s it. Now DD4T will log depending on the configuration of your logging framework.