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