Enterprise Library configuration without using App.config / Web.config

Sometimes you might want your Enterprise Library logging configuration file to kept separately and maybe you're not going to put an entry even in your web.config using [Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection].

The following codes shows how this can be accomplished:-

// Assuming the configuration file is default [loggingConfiguration] and in your current .exe directroy
FileConfigurationSource fileSrc = new FileConfigurationSource("Test.config");
// If you would like to validate your configuration //
var loggingSection = fileSrc.GetSection("loggingConfiguration");
LogWriterFactory wfac = new LogWriterFactory(new FileConfigurationSource("Test.config"));
var Writer = wfac.Create();
LogEntry logEntry = new LogEntry();
logEntry.Message = "Life";

Your new configuration file is called Test.config and its contents the same when you configure it using Enterprise Library Configuration tool.


Popular posts from this blog

OpenCover code coverage for .Net Core

ionic2 cordova build android - Unable resolve gradle 2.2.3

Using Custom DLL with IronPython / Scripts