将web或者winform的错误信息 已txt的形式 保存到本地 或者服务器上, 拿去直接用。
[C#] 纯文本查看 复制代码 /// <summary>
/// 写日志
/// </summary>
/// <param name="strMsg"></param>
/// <param name="strFileName"></param>
public static void WriteLogContent(string strFileName,string strMsg)
{
try
{
strMsg += " " + System.DateTime.Now + "\r\n";
string strPath = System.AppDomain.CurrentDomain.BaseDirectory + "/" + strFileName;
if (!File.Exists(strPath))
{
Directory.CreateDirectory(strPath);
}
string sname = System.DateTime.Now.ToString("yyyy-MM-dd");
FileStream fs = new FileStream(strPath + "/" + sname + ".txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.Write(strMsg);
sw.Flush();
sw.Close();
}
catch
{ }
}
|