How to implement Entlib in Class library

Topics: Logging Application Block
Jul 18, 2014 at 11:12 AM
How to implement Entlib in Class library project and using this class library reference to Windows form application project for logging error
Jul 21, 2014 at 6:09 AM
Edited Jul 21, 2014 at 6:09 AM
One important task to do before using the Logging Block is to bootstrap the block before using the block. Is the class library "self configuring" or will it rely on the app.config of the Windows forms application? If the former then you can use a FileConfigurationSource (or programmatic configuration). One way would be to expose the LogWriter as a Lazy<T> and bootstrap before first use:
    public class LogWriterHelper
        public Lazy<LogWriter> Logger = new Lazy<LogWriter>(() =>
            FileConfigurationSource configSource = new FileConfigurationSource("Entlib.config");
            LogWriterFactory logWriterFactory = new LogWriterFactory(configSource);
            return logWriterFactory.Create();
There are many variations (e.g. Factory class) on the above that you could use depending on the rest of the appliation design, coding standards, etc.

Randy Levy
Enterprise Library support engineer
Support How-to