#region 写错误日志
/// <summary>
/// 写错误日志
/// </summary>
/// <param name="errorMsg"></param>
/// <param name="LogPath">文件夹后面需要加上" / "符号,如:"../ErrorLog/"</param>
public static void WriteErrorLog(string errorMsg, string LogPath)
{
Common.WriteErrorLog(errorMsg, LogPath);
}
#endregion
在Web端调用日志记录方法:
try
{
}
catch (Exception ex)
{
WriteErrorLog("消息内容" + ex.Message.Replace(Environment.NewLine, string.Empty), HttpContext.Current.Server.MapPath("ErrorLog\\"));
}
#region 写错误日志
/// <summary>
/// 写错误日志
/// </summary>
/// <param name="errorMsg"></param>
/// <param name="LogPath">日志路径(仅文件夹)</param>
public static void WriteErrorLog(string errorMsg, string LogPath)
{
try
{
string FileName = String.Format("{0:yyyyMMdd}", DateTime.Now) + ".txt";
string FileFullPath = LogPath + FileName;
string WriteText = string.Empty;
if (File.Exists(FileFullPath))
{
StreamWriter writer = new StreamWriter(FileFullPath, true, System.Text.Encoding.GetEncoding("GB2312"));
writer.WriteLine(String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now) + " >>>>>> " + errorMsg);
writer.Close();
}
else
{
FileStream NewText = File.Create(FileFullPath);
NewText.Close();
StreamWriter writer = new StreamWriter(FileFullPath, true, System.Text.Encoding.GetEncoding("GB2312"));
writer.WriteLine(String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now) + ">>>>>>" + errorMsg);
writer.Close();
}
}
catch
{
}
}
#endregion