lunes, 10 de junio de 2013

asynch log vs normal log

Some time ago, my program manager said to me that, remove the system logger, because, made the web application slower.

Yesterday I thought, I can write an asynch logger for improving the performance of the application in c# 4.0, with Visual Studio 2010.

The main idea is this:


public void Write(string message)
{
    Task.Factory.StartNew(() => WriteTheMessage(message)); 
}

private static void WriteTheMessage(string message)
{
    lock (_locker)
    {
        using (StreamWriter writer = File.AppendText(path))
        {
            writer.WriteLine(message);
        }
    }
}


All the code

A simple test:




No hay comentarios:

Publicar un comentario