• c# 写txt


    public static void WriteErrorLogDataInteraction(string sLog, string titleLog)
            {
                try
                {
                    string logPath = ConfigurationSettings.AppSettings["LogPath"]; //通过配置文件记录错误日志位置
                    if (string.IsNullOrEmpty(logPath))
                    {
                        logPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;//配置文件安装目录
                    }
                    DateTime dt = DateTime.Now;
                    string logfile = new StringBuilder(logPath).Append(DateTime.Now.ToString("yyyy-MM")).Append(".txt").ToString();
                    if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(logfile)))
                    {
                        System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(logfile));
                    }
                    if (!File.Exists(logfile))
                    {
                        FileStream fs = System.IO.File.Create(logfile);
                        fs.Close();
                    }
                    using (StreamWriter sw = new StreamWriter(logfile, true))
                    {
                        sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":");
                        sw.WriteLine("Title: " + titleLog);
                        sw.WriteLine("Message:" + sLog);
                        sw.WriteLine();
                        sw.Close();
                    }
                }
                catch
                { }
            }

    方式二、

    string a = rea.ToString();
    
            StreamWriter bb = new StreamWriter("c:\\bbb.xml");
    
            bb.Write(a);
    
            bb.Close();
  • 相关阅读:
    最大回文子串
    找出不含重复字符的最长子串的长度
    链表表示的2个数相加
    如何胜任一个小型公司的技术总监?我的感想
    React 的坑
    MobX 学习
    摘要
    AI 帮助涂鸦
    计算机的前世今生
    常用编辑器实用技巧(pycharm、sublimeText、vim、vscode、Jupyter)
  • 原文地址:https://www.cnblogs.com/honghong75042/p/3071369.html
Copyright © 2020-2023  润新知