Where does the Enterprise Library 6 configuration belong?

Topics: Exception Handling Application Block, General discussion, Logging Application Block
May 29, 2013 at 2:37 AM
I am new to the Enterprise Library and the .NET world in general. I read in the Developer's Guide for Enterprise Library 6 that the preferred method of configuration for things like the Logging Application Block is programmatic as opposed to declarative, so I am trying to follow that example.

I have a MVC 4 application and I am wondering where the code for the configurations of things like the Logging Application Block and Exception Handling Block belong. Is it in the global.asax file?
May 29, 2013 at 3:15 AM
Edited May 29, 2013 at 11:43 PM
In general you would want to configure the blocks at application startup. For a web application, Application_Start in global.asax would be a reasonable place. This could depend on your design, though. If you are using a DI container then you would want to initialize the blocks at the same time the container is created so that the appropriate objects (e.g. LogWriter) can be registered in the container. This might be in a custom IControllerFactory or a class that extends DefaultControllerFactory depending on the design.

If you think you may have a standard Enterprise Library configuration (e.g. standard logging categories or listeners) that might be shared between projects/applications you might want to encapsulate that configuration logic so that it can be re-used.

Randy Levy
Enterprise Library support engineer
Support How-to
May 29, 2013 at 11:39 PM
VERY good information. Thanks Randy.