zoukankan      html  css  js  c++  java
  • 写日志的简单方法,临时用用很方便

    public static void WriteLog(string msg)
            {
                FileStream fs = null;
                StreamWriter sw = null;
    
                try
                {
                    var basePath = AppDomain.CurrentDomain.BaseDirectory;
                    if (!basePath.EndsWith("/"))
                        basePath += "/";
    
                    var logFile = basePath + DateTime.Now.ToString("yyyyMMdd") + "_debug.log";
                    if (!File.Exists(logFile))
                        File.CreateText(logFile).Dispose();
    
                    fs = new FileStream(logFile, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
                    sw = new StreamWriter(fs, Encoding.UTF8);
    
                    sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.fff"));
                    sw.WriteLine(msg);
                    sw.WriteLine("-------------------------------------");
                    sw.Flush();
                    fs.Flush();
                }
                catch { }
                finally
                {
                    if (sw != null)
                    {
                        try { sw.Close(); sw.Dispose(); } catch { }
                    }
                    if (fs != null)
                    {
                        try { fs.Close(); fs.Dispose(); } catch { }
                    }
                }
            }
  • 相关阅读:
    10.21SQL注入
    10.15计网相关
    10.11php+mysql
    10.10 接在10.8随笔中
    10.9 利用微信dll反弹shell复现
    10.8php续
    9.29 接9.27PHP相关
    java泛型
    java集合之Map接口
    java集合之Collection接口
  • 原文地址:https://www.cnblogs.com/itjeff/p/10536096.html
Copyright © 2011-2022 走看看