返回首页
当前位置: 主页 > 网络编程 > .Net实例教程 >

动态创建日志文件写日志程序代码

时间:2010-10-29 00:48来源:知行网www.zhixing123.cn 编辑:麦田守望者

private static string logpath = System.Windows.Forms.Application.StartupPath;
public static void WriteLog(string businessContent, string flieName, string functionName, string description, Wapdm.Utility.Enum.LogLevel level)
{
#region

try
{
string strDumpPath = logpath+"\\log";
lock (typeof(LogWrite))
{
if (!Directory.Exists(strDumpPath))
{
Directory.CreateDirectory(strDumpPath);
}
using (StreamWriter sw = new StreamWriter(strDumpPath + "\\" + DateTime.Now.ToString("yyyyMMdd") + ".log", true))
{
string context = "业务:" + businessContent + ";\r\n文件名:" + flieName + ";\r\n函数名:" + functionName + ";\r\n描述:" + description;
sw.WriteLine(DateTime.Now.ToString());
sw.WriteLine(context);
sw.WriteLine(" ");
sw.WriteLine("-----------------------End---------------------");
}
}

}
catch
{

}
#endregion
 

------分隔线----------------------------
标签(Tag):C# C#实例教程 c#基础教程 C#源码
------分隔线----------------------------
推荐内容
猜你感兴趣