StringBuilder MailLog = new StringBuilder();
string logPath = txtFile + str + DateTime.Now.ToString("yyyyMMdd") + ".txt";
Write(logPath, Context.DateFormat + " - " + message);
public static void Write(string filePath, string message, bool isNewline = true, Encoding encoding = null, bool append = true)
{
encoding = encoding ?? SlEncoding.Default;
try
{
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
}
catch { }
using (var streamWriter = new StreamWriter(filePath, append, encoding))
{
if (isNewline)
{
streamWriter.WriteLine(message);
}
else
{
streamWriter.Write(message);
}
streamWriter.Flush();
}
}