我有一个错误,
“无法写入已关闭的 TextWriter。”
代码:
public class Logs
{
static string File_Path= "";
static public FileStream fs;
static public StreamWriter sw;
public static void Initialize(string path)
{
File_Path = path;
fs = new FileStream(File_Path, FileMode.Append, FileAccess.Write);
sw = new StreamWriter(fs);
}
public static void info_log(string msg)
{
sw.WriteLine("{0} [INFO] : {1}",DateTime.Now.ToString(),msg);
sw.WriteLine(" ");
sw.Close();
sw.Flush();
}
public static void error_log(Exception ex)
{
sw.WriteLine("{0} [ERROR] : {1}", DateTime.Now.ToString(), ex.Message);
sw.WriteLine("StackTrace : {0}:", ex.StackTrace);
sw.WriteLine(" ");
sw.Close();
sw.Flush();
}
public static void warning_log(string msg)
{
sw.WriteLine("{0} [WARNING] : {1}", DateTime.Now.ToString(), msg);
sw.WriteLine(" ");
sw.Close();
sw.Flush();
}
}