title: Which pattern to use for logging? Dependency Injection or Service Locator?
body: <p>Consider this scenario. I have some business logic that now and then will be required to write to a log. </p>
  
  <pre><code>interface ILogger
  {
      void Log(string stuff);
  }
  
  interface IDependency
  {
      string GetInfo();
  }
  
  class MyBusinessObject
  {
      private IDependency _dependency;
  
      public MyBusinessObject(IDependency dependency)
      {
          _dependency = dependency;
      }
  
      public string DoSomething(string input)
      {
          // Process input
          var info = _dependency.GetInfo();
          var intermediateResult = PerformInterestingStuff(input, info);
  
          if (intermediateResult== "SomethingWeNeedToLog")
          {
              // How do I get to the ILogger-interface?
          }
  
          var result = PerformSomethingElse(intermediateResult);
  
          return result;
      }
  }
  </code></pre>
  
  <p>How would you get the ILogger interface? I see two main possibilities;</p>
  
  <ol>
  <li>Pass it using Dependency Injection on the constructor.</li>
  <li>Get it via a singleton Service Locator.</li>
  </ol>
  
  <p>Which method would you prefer, and why? Or is there an even better pattern? </p>
  
  <p><strong>Update:</strong>
  Note that I don't need to log ALL method calls. I only want to log a few (rare) events that may or may not occur within my method.</p>