zoukankan      html  css  js  c++  java
  • c#写日志

    方法一:以日期为日志文件名,输出txt文件

    public void WriteLog(string msg) 

        string filePath = AppDomain.CurrentDomain.BaseDirectory + "Log"; 
        if (!Directory.Exists(filePath)) 
        { 
            Directory.CreateDirectory(filePath); 
        } 
        string logPath = AppDomain.CurrentDomain.BaseDirectory + "Log\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt"; 
        try 
        { 
            using (StreamWriter sw = File.AppendText(logPath)) 
            { 
                sw.WriteLine("消息:" + msg); 
                sw.WriteLine("时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); 
                sw.WriteLine("**************************************************"); 
                sw.WriteLine(); 
                sw.Flush(); 
                sw.Close(); 
                sw.Dispose(); 
            } 
        } 
        catch (IOException e) 
        { 
            using (StreamWriter sw = File.AppendText(logPath)) 
            { 
                sw.WriteLine("异常:" + e.Message); 
                sw.WriteLine("时间:" + DateTime.Now.ToString("yyy-MM-dd HH:mm:ss")); 
                sw.WriteLine("**************************************************"); 
                sw.WriteLine(); 
                sw.Flush(); 
                sw.Close(); 
                sw.Dispose(); 
            } 
        } 

  • 相关阅读:
    HPU第二次个人训练
    2019CCPC江西省赛
    CodeForces-913C 派对柠檬水
    [Codeforces Round #737 (Div. 2)] C Moamen and XOR (T1 D1
    E-Tree Xor_2021牛客暑期多校训练营4
    Educational Codeforces Round 107 (Rated for Div. 2) E Colorings and Dominoes
    状压dp 练习
    权值线段树模板(自用)
    Planar Reflections
    Codeforces Round #688 (Div. 2) D Checkpoints
  • 原文地址:https://www.cnblogs.com/zmbhfly/p/9914416.html
Copyright © 2011-2022 走看看