Note that there are some explanatory texts on larger screens.

plurals
  1. POInstalling Windsor Logging Facility into a library
    primarykey
    data
    text
    <p>I'm developing a framework where I've put lots of logging throughout. I used Castle Windsor's ILogger through this property pattern:</p> <pre><code>namespace Framework { public class SomeClass { private ILogger _logger = NullLogger.Instance; public ILogger Logger { get { return _logger; } set { _logger = value; } } public void DoSomething() { Logger.Info("Doing something."); } //... } } </code></pre> <p>I also provide an installer from within the framework:</p> <pre><code>namespace MyFramework { public class LoggerInstaller : IWindsorInstaller { private readonly string _configPath; public LoggerInstaller(string configPath) { _configPath = configPath; } public void Install(IWindsorContainer container, IConfigurationStore store) { container.AddFacility("logging", new LoggingFacility(LoggerImplementation.Log4net, _configPath)); //I've also tried this one: //container.AddFacility&lt;LoggingFacility&gt;(f =&gt; f.LogUsing(LoggerImplementation.Log4net).WithConfig(_configPath)); } } } </code></pre> <p>This project is then referenced from other projects. For example, in the test project, I'll construct a test by first installing the logger. I do this with an abstract class that all of my long running tests extend:</p> <pre><code>namespace Framework.Test { public abstract class Log4NetLoggedTest { private const string ConfigFilePath = "log4net.config"; protected ILogger Logger { get; set; } protected IWindsorContainer Container { get; set; } protected Log4NetLoggedTest() { Container = new WindsorContainer(); Container.Install(new LoggerInstaller(ConfigFilePath)); Logger = Container.Resolve&lt;ILogger&gt;(); } ~Log4NetLoggedTest() { Container.Dispose(); } } } </code></pre> <p>So that my test looks like this:</p> <pre><code>namespace Framework.Test { [TestFixture] public class MyLongRunningTest : Log4NetLoggedTest { [Test] [Category("LongRunning")] public void ModelConvergesForS50() { Logger.Info("Starting test..."); var obj = new SomeClass(); obj.DoSomething(); // ... } } } </code></pre> <p>The test's ILogger Logger gets resolved and set properly, so in this example I get the "Starting test..." but not the "Doing something." The SomeClass's ILogger stays as a NullLogger.</p> <p>Please help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload