ASP.NET: Einfache Log-Datei schreiben

Muss mal schnell was mitgeloggt werden, bietet sich z.B. der StreamWriter an.

using System.IO;
...
string fileName = String.Format("log-{0}.txt", DateTime.Now.ToString("yyyy-MM-dd"));
string dataRow = String.Format("{0}; {1}; {2}", DateTime.Now, var1, var2);

StreamWriter myFile = new StreamWriter(Server.MapPath("~/App_Data/" + fileName), true);
myFile.WriteLine(dataRow);
myFile.Close();

ASP.NET

November 2009 | Permalink | Feedback