zoukankan      html  css  js  c++  java
  • 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();
  • 相关阅读:
    CentOS搭建LAMP环境
    CentOS下为Apache部署Symantec SSL证书并实现强制https访问
    [Raspi]树莓派4B装机使用上手指南
    [FPGA]Verilog利用PWM调制完成RGB三色彩虹呼吸灯
    [FPGA]浅谈LCD1602字符型液晶显示器(Verilog)
    [FPGA]Verilog实现JK触发器组成的8421BCD码十进制计数器
    [FPGA]Verilog实现可自定义的倒计时器(24秒为例)
    [FPGA]Verilog实现8位串并转换器HC595
    [FPGA]Verilog实现寄存器LS374
    STM32F407之USART
  • 原文地址:https://www.cnblogs.com/honghong75042/p/3071369.html
Copyright © 2011-2022 走看看