public class LogHelper
{
private static object objLock = new object();
public void SaveLogToFile(string message,string functionName)
{
lock (objLock)
{
string filePath = Application.StartupPath +"\\log.txt";
StreamWriter sw = null;
if (!File.Exists(filePath))
{
sw = File.CreateText(filePath);
}
else
{
sw = File.AppendText(filePath);
}
string info = "[" + System.DateTime.Now.ToString() + "][" + functionName + "] " + message;
Console.WriteLine(info);
sw.WriteLine(info);
sw.Close();
}
}
}