zoukankan      html  css  js  c++  java
  • 写logo

     public static void WriteErrorLog(Exception ex)
            {
                string LOG_FOLDER = AppDomain.CurrentDomain.BaseDirectory + "Log";
                try
                {
                    //日志文件路径
                    filePath = LOG_FOLDER + "\\" + "ErrorLog" + ".txt";
                    if (!System.IO.Directory.Exists(LOG_FOLDER))
                    {
                        Directory.CreateDirectory(LOG_FOLDER);
                    }
                    if (!File.Exists(filePath))//如果文件不存在
                    {
                        File.Create(filePath);
                    }
                    StreamWriter sw = File.AppendText(filePath);
                    sw.WriteLine("-------------------------------------------------------------------------------------");
                    sw.WriteLine("Date:" + DateTime.Now.ToShortDateString() + " Time:" + DateTime.Now.ToShortTimeString());
                    sw.WriteLine(ex.Message);
                    sw.WriteLine(ex.StackTrace);
                    sw.WriteLine();
                    sw.Close();
                }
                catch (Exception)
                {
                    //throw;
                }
            } 

    上面的,经常出现"**文件正由另一进程使用,因此该进程无法访问该文件"!!!!!!!!!!!!!!!

    下面:

    publicstaticvoid WriteLog(string _msg)
        {
           
    string folder = System.Web.HttpContext.Current.Server.MapPath("~/log");
           
    if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);

           
    string filename = folder +"/"+ DateTime.Now.ToShortDateString() +".txt";
           
    if (File.Exists(filename))
            {
                FileStream fs
    =new FileStream(filename, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
                StreamWriter sr
    =new StreamWriter(fs);
                sr.WriteLine(DateTime.Now.ToString(
    "HH:mm:ss") +"\t"+ _msg);
                sr.Close();
                fs.Close();
            }
           
    else
            {
                FileStream fs
    =new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                StreamWriter sr
    =new StreamWriter(fs);
                sr.WriteLine(DateTime.Now.ToString(
    "HH:mm:ss") +"\t"+ _msg);
                sr.Close();
                fs.Close();
            }      
        }

  • 相关阅读:
    HP Nonstop SQLMX (SPJ) Stored Procedure in Javas Getting Started
    Term of Wall Street
    iOS自带地图纠偏问题
    Android 界面排版的5种方式
    Android底部导航栏
    Android中Intent传值与Bundle传值的区别详解
    Android开发EditText属性
    从点击一个链接到浏览器显示页面,这个过程中发生了什么?
    HTML的常用标签属性及使用时需注意的一些细节
    写一个简单的脚本,并在脚本生成的的文件中添加内容
  • 原文地址:https://www.cnblogs.com/gerryge/p/2567711.html
Copyright © 2011-2022 走看看