zoukankan      html  css  js  c++  java
  • C#输出log信息

    在写程序的过程中,有时候我们需要添加一些log信息,这个时候,可以采用下面的方法来实现。

            public static void WriteLog(string ExtraMsg, Exception e)
            {
               string logPath = Environment.CurrentDirectory + "\Log";
                if (!Directory.Exists(logPath))
                {
                    Directory.CreateDirectory(logPath);
                }
    
               string logFilePath = Path.Combine(logPath, string.Format("{0}.log", DateTime.Now.Date.ToString("yyyyMMdd")));
               if (e is System.Threading.ThreadAbortException)
                   return;
    
               string strMsg = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "   " + e.Message;
               string detailMsg = string.Format("类型:{0}
    堆栈:{1})", e.GetType().Name, e.StackTrace);
               using (StreamWriter sw = new StreamWriter(logFilePath, true))
               {
                   sw.WriteLine(strMsg);
                   sw.WriteLine(ExtraMsg);
                   sw.WriteLine(detailMsg);
                   sw.WriteLine();
                   sw.Close();
               }
            }
    WriteLog
  • 相关阅读:
    校验规则,纯数字。几位有效数字,保留几位小数
    银行卡校验规则(Luhn算法)
    forEach兼容ie8
    node.js
    gulp
    observer
    webpack.config.js 配置
    内存泄漏(Memory Leak)
    cdn
    前端 各种插件的官网
  • 原文地址:https://www.cnblogs.com/ningheshutong/p/4425799.html
Copyright © 2011-2022 走看看