using (StreamWriter oStreamWriter = new StreamWriter(outputFilename))
{
oStreamWriter.WriteLine(YourTextHere);
......
}
Second way:
This graphic is scaned from the book C# 3.0 in a Nutshell, 3rd Edition. This is a very good C# book, and I will say "Go and grab one".
using (FileStream oFileStream = new FileStream("Errorlog.txt", FileMode.Append))How to choose the correct FileMode? Take a look of this graph:
{
using (TextWriter oTextWriter = new StreamWriter(oFileStream))
{
oTextWriter.WriteLine("DateTime: " + DateTime.Now.ToString());
oTextWriter.WriteLine("Message: " + ex.Message);
oTextWriter.WriteLine("Source: " + ex.Source);
}
}
This graphic is scaned from the book C# 3.0 in a Nutshell, 3rd Edition. This is a very good C# book, and I will say "Go and grab one".
No comments:
Post a Comment