title: c# static class that uses another class
body: <p>I have a logger API that I can use to log to text.
  The logger has some properties that I can use to record envent types (Info, Err, etc...), source app (app1, app2, etc...) and mesg text.</p>
  
  <p>The syntax is simple and is working OK:</p>
  
  <pre><code>Logger log = new Logger();
  log.Write("Information", "SourceApplication", "Test text to log");
  </code></pre>
  
  <p>Now I m thinking creating 2 static classes, one for "General Purpose Logging" and other for "Debug Logging". The goal is to avoid to create a new instance of the logger object for each module utilization. Each class should be able to use these objects without instantiation (the static classes should take care of that automatically).</p>
  
  <p>"Debug Logging" - Can be used by any project inside the solution and should be a singleton.
  The Caller Code to use should be:</p>
  
  <pre><code>LoggerDebug.Write("Debug", "Debugger", "Test text to log");
  </code></pre>
  
  <p>General Purpose Logging - To be used by all project modules but after each utilization the static class should dispose the Logger Object 
  The Caller Code to use should be:</p>
  
  <pre><code>LoggerDebug.Write("Information", "App1", "Test text to log");
  </code></pre>
  
  <p>I tried to start with the "Debug Logging" static class, I read (<a href="http://csharpindepth.com/Articles/General/Singleton.aspx" rel="nofollow">http://csharpindepth.com/Articles/General/Singleton.aspx</a>) but I`m not sure if this is the correct way to do this...
  Can you give me some suggestions?</p>
  
  <pre><code>using System;
  using System.Diagnostics;
  using System.Collections.Generic;
  
  namespace Common
  {
      public sealed class LoggerDebug
      {
          private static LoggerDebug instance = null;
          private static readonly object padlock = new object();
          private static Logger log;
  
          static LoggerDebug Instance
          {
              get
              {
                  lock (padlock)
                  {
                      if (instance == null)
                      {
                          instance = new LoggerDebug();
                      }
                      return instance;
                  }
              }
          }
  
          public LoggerDebug()
          {
              log = new Logger();
          }
  
          public static void Write(String EventType, string appSource, string text)
          {
              log.Write(EventType, appSource, string.Format("Test {0}", text));
          }
      }
  }
  </code></pre>
  
  <p>The caller code appears like this:</p>
  
  <pre><code>LoggerDebug.Write("Information", "App1", "Test text to log");
  </code></pre>
  
  <p>When I try to run the application it crashes with:</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.NullReferenceException'
    occurred in Common.dll Additional information: Object reference not
    set to an instance of an object.</p>
  </blockquote>
  
  <p>That said the ctor is not instantiating the <code>log = new Logger();</code></p>
  
  <p>So I can correct this problem with:</p>
  
  <pre><code>private static Logger log = new Logger();
  </code></pre>
  
  <p>And commenting the ctor code</p>
  
  <pre><code>public LoggerDebug()
  {
      //log = new Logger();
  }
  </code></pre>
  
  <p>But I m confused, not sure if this is the correct way to do this, How to do this correctly?</p>
  
  <p>Any examples that I can use?</p>