日志文件的生成
? 開發(fā)系統(tǒng)過程中,大部分都要用到寫日志來跟蹤具體的調(diào)用信息,或可能出錯(cuò)時(shí),方便查找出錯(cuò)的
具體地方.目前關(guān)于日志的第三方控件非常的多,用的比較多的好象是log4net.在這我不介紹這個(gè)控件,而是用系統(tǒng)的STACKTRACE來跟蹤.CODE AS FOLLOW:
??public static? void WriteLogFileInfo()
??{???
???StreamWriter sw =new StreamWriter(( System.IO.Path.Combine(System.Environment.CurrentDirectory,System.DateTime.Now.ToString("yyyyMMdd hhmmss")+"_log" +".log")));
???m_oSt = new StackTrace(true);
???//get the prior ten frames
???for(int iCnt = 0;iCnt < m_oSt.FrameCount && iCnt <10;iCnt++)
???{
????m_sLogDetailInfo = m_oSt.GetFrame(iCnt).GetMethod().DeclaringType.FullName +":" + m_oSt.GetFrame(iCnt).GetMethod().Name;??
?
????sw.WriteLine(HostName() + "\t"+IpAddress() +"\t" +System.DateTime.Now.ToString("yyyyMMdd hhmmss")+"\t" + m_sLogDetailInfo);???
???}
???sw.Close();
???sw =null;
??}??
??private static string HostName()
??{
???m_sLogOutHostName = System.Net.Dns.GetHostName();
???return m_sLogOutHostName;
??}
??private? static string IpAddress()
??{
???m_sLogOutIpAddress = System.Net.Dns.GetHostByName(m_sLogOutHostName);
???return m_sLogOutIpAddress.AddressList[0].ToString();
??}
That's all!!???? ~.~
轉(zhuǎn)載于:https://www.cnblogs.com/huangkit/archive/2007/04/12/710338.html
總結(jié)
- 上一篇: 学习在 ArcEngine 中使用 Ge
- 下一篇: Win2000 Win2003安装卡巴斯