I want to create a log file to track some operations in my Application.In my scenario within one session I wanna to log at least 50 time per min.currently im using StremWriter to create log file.
public static StreamWriter InitializeStream(string path)
{
/*ensuring whether thread safe or not*/
lock (mylock)
{
if (null == _stream)
{
var fileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
_stream = new StreamWriter(fileStream);
return _stream;
}
return _stream;
}
}
//logging operation
StreamHandler.Log(path)
Still im bit confuse to selecting AppendAllText or StreamWriter.
Instead of StreamWriter way can i get advantage using AppendAllText Directly?(Performance)
Do not use
AppendAllText()inside the loop because it usesStremWriterinternally where stream object will be initialized and disposed on each iteration.