title: C# logging "russian dolls effect" in constructors parameters
body: <p>First, I am not sure that I use the good words to describe my problem, apologies (English is not my mother tong). </p>
  
  <p>It is about adding <em>loggers</em> to a project. 
  As it was asked, there should be several loggers and they should to be defined "dynamically". 
  So we end up with classes that have a <code>Logger</code> property. </p>
  
  <p>All constructors have though an extra parameter which is the <code>logger</code> instance passed to the constructor with the other business parameters. As we go deep inside the code, classes inside each other are using the same pattern to pass the <code>logger</code> instance. </p>
  
  <p>Sure it works, but I am not happy with it. 
  What annoys me is that the logger does not belongs to the business logic. 
  Maybe there is nothing to do with it. </p>
  
  <p>--</p>
  
  <p>More precisely this is what I am working out for the moment : </p>
  
  <ul>
  <li>There is the <code>ILogger</code> interface that defines the loggers functions (<code>LogError(string msg)</code> for example). Different Loggers will implement this interface. </li>
  <li>There is the <code>ILoggable</code> interface that will be implemented by all classes that need to do logging. This interface has a property <code>public ILogger LoggerPte</code></li>
  </ul>
  
  <p>I use a static class <code>LoggerUtility</code> with a <code>[ThreadStatic]</code> field <code>static ILogger CurrentLogger</code> and a function : </p>
  
  <pre><code>public static void SetLoggerReference(ILoggable loggableClass)
  {
      loggableClass.LoggerPte = CurrentLogger;
  }
  </code></pre>
  
  <p>Outside of the <em>loggable</em> class, the CurrentLogger is defined. </p>
  
  <p>In the constructor of a <em>loggable</em> class, I have to call <code>LoggerUtility.SetLoggerReference(this);</code></p>
  
  <p>If found this way more elegant although it might be twisted, but I would like to know if it can be possible to go further... </p>
  
  <p>I have just started to read about custom attributes, reflection and AOP. Can somebody give me a hand about how to use an attribute like <code>[Loggable]</code> to automatically make the constructor call the function <code>SetLoggerReference(this)</code> after the constructor without having explicitly to write it in the code. 
  If it is possible...</p>