您的位置:首页 > 编程语言 > C#

C#输出日志记录

2016-11-07 17:49 274 查看
string vsPath = @"C:\InterFace\";

                if (!System.IO.Directory.Exists(vsPath))

                    System.IO.Directory.CreateDirectory(vsPath);

                try

                {

                    DateTime currentTime = System.DateTime.Now;

                    vsPath = vsPath + "GS_InterFace_CodeOutPutLog" + currentTime.ToString("yyyyMMdd") + ".txt";

                    System.IO.StreamWriter sw = new System.IO.StreamWriter(vsPath, true, System.Text.Encoding.Default);

                    sw.WriteLine("记录时间:{0}", DateTime.Now.ToString());

                    sw.WriteLine("信息文本:{0}", logMessage);

                    sw.WriteLine("---------------------------------------------------------------------------------------------");

                    sw.Flush();

                    sw.Close();

                }

                catch (Exception ex)

                {

                }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: