using System; using System.Configuration; using Microsoft.Practices.EnterpriseLibrary.Logging; using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration; using Microsoft.Practices.EnterpriseLibrary.Common.Configuration; using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Fluent; namespace ServiceStack.Logging.EntLib5 { public class EntLib5Factory : LogWriterFactory, ILogFactory { /// /// Initializes a new instance of the class. /// public EntLib5Factory() { } /// /// Initializes a new instance of the class. /// /// The enterprise library 5.0 configuration file to load and watch. Supercedes any configuration found in the Config file. public EntLib5Factory(string EntLib5ConfigurationFile) { // verify provided file exists var fi = new System.IO.FileInfo(EntLib5ConfigurationFile); if (fi.Exists) { var builder = new ConfigurationSourceBuilder(); var EntLib5ConfigurationSrc = new FileConfigurationSource(EntLib5ConfigurationFile, true); builder.UpdateConfigurationWithReplace(EntLib5ConfigurationSrc); EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(EntLib5ConfigurationSrc); } } /// /// Initializes a new instance of the class. /// /// The enterprise library 5.0 configuration source to load. Supercedes any configuration found in the Config file. public EntLib5Factory(IConfigurationSource EntLib5ConfigurationSrc) { // replace any settings from App.Config with the ones in the provided config source var builder = new ConfigurationSourceBuilder(); builder.UpdateConfigurationWithReplace(EntLib5ConfigurationSrc); EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(EntLib5ConfigurationSrc); } /// /// Gets the logger. /// /// The type. /// public ILog GetLogger(Type type) { return new EntLib5Logger(type); } /// /// Gets the logger. /// /// Name of the type. /// public ILog GetLogger(string typeName) { return new EntLib5Logger(typeName); } } }