110,534
社区成员
发帖
与我相关
我的任务
分享
public static void WriteMyLog(Exception ex)
{
string LOG_FOLDER = AppDomain.CurrentDomain.BaseDirectory + "Log";
try
{
//日志文件路径
string filePath = LOG_FOLDER + "\\" + DateTime.Now.ToShortDateString() + ".log";
if (!System.IO.Directory.Exists(LOG_FOLDER))
{
Directory.CreateDirectory(LOG_FOLDER);
}
if (!File.Exists(filePath))//如果文件不存在
{
File.Create(filePath).Close();
}
StreamWriter sw = File.AppendText(filePath);
sw.WriteLine("-------------------------------------------------------------------------------------");
sw.WriteLine("Date:" + DateTime.Now.ToShortDateString() + " Time:" + DateTime.Now.ToShortTimeString());
sw.WriteLine(ex.Message);
sw.WriteLine(ex.StackTrace);
sw.Close();
}
catch
{ }