Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 01, 2010 10:35 PM by SaNtoG
Nov 01, 2010 07:19 PM|LINK
I have been searching for a while now without success. On how when using EntLib 5.0 Logging, Data; to be able to set the database (i.e. the connection string) at runtime for a Database Trace Listener. The reason
being we will have the same configurations on all levels of the environments (dev, test, stage, prod), but the connection string is different for each and we do not store the connection string data in the config file. The connection string data is loaded using
a custom configuration manager for security reasons.
Any help and any code sample much appreciated.
Enterprise Library 5.0
Nov 01, 2010 10:35 PM|LINK
Found "a way" to complete what I was wanting to do. If anyone has any suggestions or improvements please reply.
//Find the configuration file in with the calling assembly and get the path.
//Do not feel this is ideal.
var assembly = Assembly.GetCallingAssembly();
var path = Path.Combine(Path.GetDirectoryName(assembly.Location),
//Load the config file and make sure it gets cleaned up.
using(var fileSource = new FileConfigurationSource(path))
//Create the config builder and configure the sections you want to override.
var configBuilder = new ConfigurationSourceBuilder();
//Update the file source configuration section with the ones in the builder.
//Set the current container to the one we just created.
//Get instance of log writer in this case.
_logWriter = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();