椤圭洰鍙兘浼氱敤鍒扮殑杈呭姪鏂规硶

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了椤圭洰鍙兘浼氱敤鍒扮殑杈呭姪鏂规硶相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%5cn' title=' '>    toe   sha   鏂规硶   catch   path   datetime   sage   demo   

鍐欐棩蹇楃殑鏂规硶锛?/p>

 public static void WriteLog(Exception e)
        {
            try
            {
                var fileName = DateTime.Now.ToString("HH:mm:ss").Replace(鈥?鈥? 鈥榑鈥?.Replace(鈥?鈥?鈥榑鈥?;
                var physicalPath = "E:/鏈満demo/ConsoleApp2/log/"+DateTime.Now.ToString("yyyy-MM-dd")+"/Exceptionlog_" + fileName + ".log";
                if (!File.Exists(physicalPath))
                {
                    var fcreat = File.Create(physicalPath);
                    fcreat.Close();
                }
                using (FileStream aFile = new FileStream(physicalPath, FileMode.Open))
                {
                    StreamReader sr = new StreamReader(aFile, Encoding.GetEncoding("GB2312"));
                    var content = sr.ReadToEndAsync().Result;
                    #region 鍐欏叆寮傚父淇℃伅
                    using (StreamWriter sw = new StreamWriter(aFile, Encoding.UTF8))
                    {
                        sw.Write(content + "
" + DateTime.Now.ToString() + "锛歕r
" + e.Message.ToString());  //杩欓噷鏄啓鍏ョ殑鍐呭
                        sw.Flush();
                        sw.Close();
                    }
                    #endregion
                    sr.Close();
                }
                    
                
            }
            catch (Exception ex)
            {
                throw (ex);
            }

        }

銆€銆€

以上是关于椤圭洰鍙兘浼氱敤鍒扮殑杈呭姪鏂规硶的主要内容,如果未能解决你的问题,请参考以下文章

浣跨敤Python杩囩▼涓亣鍒扮殑涓€浜涘潙鍙婂叾瑙e喅鏂规硶锛堟寔缁洿鏂帮級

vue椤圭洰鍙妚uex浣跨敤

瑙e喅java web 椤圭洰鍙戝竷webservice鎺ュ彛

koa,express,node閫氱敤鏂规硶杩炴帴MongoDB

Maven椤圭洰鎵撳寘鎴愬彲鎵цJar鏂囦欢