Constructor not being called
<p>I cannot figure out why I keep getting a null ref on filename when I'm clearly calling this singleton and it should be calling the Logger() to set the filename variable:</p>

<pre><code>public class Logger
{
private static Logger defaultLogger = null;
readonly string filename;

public static Logger DefaultLogger
{
    get
    {
        // Check for valid instance
        if (defaultLogger == null) 
            defaultLogger = new Logger();

        // Return instance
        return defaultLogger;
    }
}

private Logger()
{
    filename = ConfigurationManager.AppSettings["MyLogPath"];
}


 public string Filename
 {
  get { return this.filename; }
 }

 public void Write(EntryType type, string data)
 {
  lock (this)
  {
   using (StreamWriter writer = new StreamWriter(filename, true))
   {
   //do something
   }
  }
 }
}
</code></pre>

<p>Here's how I'm calling this class:</p>

<pre><code>Logger.DefaultLogger.Write(EntryType.Error, e.ToString());
</code></pre>

<p>So I get this error during runtime saying that filename is null:</p>

<pre><code> Value cannot be null.
Parameter name: path
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: path

Source Error:

Line 49: 
Line 50: 
Line 51:     public string Filename
Line 52:     {
Line 53:      get { return this.filename; }
</code></pre>

<p>This was our original code (I did not write this), same problem:</p>

<pre><code>public class Logger
{
 public static Logger DefaultLogger = new Logger();

string filename;

 public Logger()
 {
    filename = ConfigurationManager.AppSettings["LogPath"];
 }

 public Logger(string filename)
 {
  this.filename = filename;
 }

 public string Filename
 {
  get { return this.filename; }
 }

 public void Write(LogEntryType type, string data)
 {
  lock ()
  {
   using (StreamWriter writer = new StreamWriter(filename, true))
   {
    ...
  }
 }
}
</code></pre>
