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();
            }
        }

posted on 2016-11-21 17:39  菜鸟Only  阅读(409)  评论(0编辑  收藏  举报