C# 保存日志

项目中很多地方需要保存当前信息,或者打印文件流特将此方法保存

      /// <summary>
        /// 添加本地日志
        /// </summary>
        /// <param name="path"></param>
        /// <param name="content"></param>
        public static void WriteLog( string content)
        {
            try
            {
               string path = Application.StartupPath + "\\logs\\"; ;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                path = path + @"\log.txt";
                if (!File.Exists(path))
                {
                    File.Create(path);
                }
                content = content + "\r\n";
                File.AppendAllText(path, content);
            }
            catch(Exception ex) 
            { 
            
            }
        }

 

posted @ 2022-02-26 15:26  开发晋级之路  阅读(250)  评论(0)    收藏  举报