C#日志文件的生成

来源:互联网 发布:c语言函数库大全 chm 编辑:程序博客网 时间:2024/04/29 22:35

        public static void WriteLogFileInfo()
        {
            StreamWriter sw = new                              StreamWriter((System.IO.Path.Combine(System.Environment.CurrentDirectory, System.DateTime.Now.ToString("yyyyMMdd hhmmss") + "_log" + ".log")));
            StackTrace m_oSt = new StackTrace(true);
            //get the prior ten frames
            for (int iCnt = 0; iCnt < m_oSt.FrameCount && iCnt < 10; iCnt++)
            {
                string 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("d") + "/t" + m_sLogDetailInfo);
            }
            sw.Close();
            sw = null;

        }

原创粉丝点击