Simple MultiThread Safe Log Class

Posted by Robert on Stack Overflow See other posts from Stack Overflow or by Robert
Published on 2010-06-02T03:56:02Z Indexed on 2010/06/02 4:03 UTC
Read the original article Hit count: 165

Filed under:

What is the best approach to creating a simple multithread safe logging class? Is something like this sufficient?

public class Logging
{
    public Logging()
    {
    }

    public void WriteToLog(string message)
    {
        object locker = new object();

        lock(locker)
        {
            StreamWriter SW;
            SW=File.AppendText("Data\\Log.txt");
            SW.WriteLine(message);
            SW.Close();
        }
    }
}

© Stack Overflow or respective owner

Related posts about c#