Created
January 6, 2011 16:41
-
-
Save jmeridth/768136 to your computer and use it in GitHub Desktop.
bootstrapping structuremap and log4net
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.IO; | |
| using log4net; | |
| using log4net.Config; | |
| using StructureMap; | |
| namespace Common.Infrastructure | |
| { | |
| public static class BootStrapper | |
| { | |
| private static ILog _logger; | |
| public static void Configure(Action structureMapDsl) | |
| { | |
| ConfigureLogger(); | |
| ConfigureContainer(structureMapDsl); | |
| _logger.Info("Bootstrap Complete"); | |
| } | |
| public static void Configure() | |
| { | |
| Configure(null); | |
| } | |
| public static void ConfigureLogger() | |
| { | |
| XmlConfigurator.Configure(new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config"))); | |
| _logger = LogManager.GetLogger(typeof (BootStrapper)); | |
| _logger.Info("Logging Configured"); | |
| } | |
| public static void ConfigureContainer() | |
| { | |
| ConfigureContainer(null); | |
| } | |
| public static void ConfigureContainer(Action structureMapDsl) | |
| { | |
| if(structureMapDsl == null) | |
| { | |
| //use StructureMap.config file xml contents | |
| ObjectFactory.Initialize(x => x.UseDefaultStructureMapConfigFile = true); | |
| } | |
| else | |
| { | |
| //use passed in DSL method | |
| structureMapDsl.Invoke(); | |
| } | |
| ObjectFactory.AssertConfigurationIsValid(); | |
| if (_logger.IsDebugEnabled) | |
| { | |
| _logger.DebugFormat("Container Configuration\n{0}", ObjectFactory.WhatDoIHave()); | |
| } | |
| _logger.Info("Container Configured"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment