文档库 最新最全的文档下载
当前位置:文档库 › C#将异常打印到程序根目录下的LOG文件

C#将异常打印到程序根目录下的LOG文件

//C#将异常打印到程序根目录下的LOG文件
//作者 廖XX
private void WriteLog(Exception ex, string LogAddress,string dstype,string dsactiontype,string dscontent)
{
//AppDomain.CurrentDomain.BaseDirectory + "ErrLog\\";
//如果日志文件为空,则默认在Debug目录下新建 YYYY-mm-dd_Log.log文件
if (LogAddress == "")
{
LogAddress = Environment.CurrentDirectory + '\\' + DateTime.Now.Year + '-' + DateTime.Now.Month + '-' + DateTime.Now.Day + "_Log.log";
}
//把异常信息输出到文件
StreamWriter sw = new StreamWriter(LogAddress, true);
sw.WriteLine("当前时间:" + DateTime.Now.ToString());
sw.WriteLine("查询类型:" + dstype);
sw.WriteLine("查询对象:" + dsactiontype);
sw.WriteLine("查询内容:" + dscontent);
sw.WriteLine();
sw.Close();
}

相关文档