Designing a better logger class Could you please critisize the logger class below? Can it be used in a multi threaded web environment? If not how can I improve it? Is there anything wrong with locking in WriteToLog method or multithreading in FlushLog method?

public class Logger
{
    private static Logger instance;
    private static Queue&lt;LogData&gt; logQueue;
    private static string logDir = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["LogDirectory"]);
    private static string logFile = "log.txt";
    private static int maxLogAge = Int32.Parse(ConfigurationManager.AppSettings["LogMaxAge"]);
    private static int queueSize = Int32.Parse(ConfigurationManager.AppSettings["LogQueueSize"]);
    private static DateTime LastFlushed = DateTime.Now;

    private Logger() { }

    public static Logger Instance
    {
        get
        {
            if (instance == null)
            {
                instance = new Logger();
                logQueue = new Queue&lt;LogData&gt;();
            }
            return instance;
        }
    }

    public void WriteToLog(string message)
    {
        lock (logQueue)
        {
            LogData logEntry = new LogData(message);
            logQueue.Enqueue(logEntry);

            if (logQueue.Count &gt;= queueSize || DoPeriodicFlush())
            {
                FlushLog();
            }
        }            
    }

    private bool DoPeriodicFlush()
    {
        TimeSpan logAge = DateTime.Now - LastFlushed;
        if (logAge.TotalSeconds &gt;= maxLogAge)
        {
            LastFlushed = DateTime.Now;
            return true;
        }
        else
        {
            return false;
        }
    }

    private void FlushLog()
    {
        System.Threading.ThreadPool.QueueUserWorkItem(q =&gt; {
            while (logQueue.Count &gt; 0)
            {
                LogData entry = logQueue.Dequeue();
                string logPath = logDir + entry.LogDate + "_" + logFile;

                using (System.IO.StreamWriter file = new System.IO.StreamWriter(logPath, true, System.Text.Encoding.UTF8))
                {
                    file.WriteLine(string.Format("{0}\t{1}", entry.LogTime, entry.Message));
                }
            }
        });
    }

    ~Logger()
    {
        FlushLog();
    }
}

public class LogData
{
    public string Message { get; set; }
    public string LogTime { get; set; }
    public string LogDate { get; set; }

    public LogData(string message)
    {
        Message = message;
        LogDate = DateTime.Now.ToString("yyyy-MM-dd");
        LogTime = DateTime.Now.ToString("HH:mm:ss.fff tt");
    }
}


Thanks in advance,
This code is not thread safe.  You synchronize (lock) while adding to the queue, but your code which removes from the code does not lock the queue, and will always run on a background thread, which is going to cause potential race conditions.

If you really must write your own logging, I would, at the least, look into using ConcurrentQueue&lt;T&gt; to avoid the need for locking on adding.  BlockingCollection&lt;T&gt; would make this far simpler, as you could just have a thread call GetConsumingEnumerable() to process items as they're added.

That being said, logging is something that's been handled many times, and handled well.  You'd be far better off using something like the new Semantic Logging Application Block (from P&amp;P) or even log4net.