zoukankan      html  css  js  c++  java
  • EXT编写日志文件

     static long m_nIndex = 0;        

    /// 写入日志文件       

    [DirectMethod]        

    public static void WriteLogFile(string input)        

    {                        

      try            

      {                

        ///指定日志文件的目录             

        string fname = "F:\\公司项目\\webserviceLogFile.txt";                                 

        ///定义文件信息对象

                  FileInfo finfo = new FileInfo(fname);

                   if (!finfo.Exists)                

        {                    

          FileStream fs;                    

          fs = File.Create(fname);                    

          fs.Close();                    

          finfo = new FileInfo(fname);                

        }

                   ///判断文件是否存在以及是否大于2K

                    if (finfo.Length > 1024 * 1024 *5)

                    {

                        ///文件超过10MB则重命名

                        File.Move(Directory.GetCurrentDirectory() + "\\LogFile.txt",

            Directory.GetCurrentDirectory() + DateTime.Now.TimeOfDay + "\\LogFile.txt");

                    }

                    ///创建只写文件流

                    using (FileStream fs = finfo.OpenWrite())

                    {

             ///根据上面创建的文件流创建写数据流

                        StreamWriter w = new StreamWriter(fs);

                        ///设置写数据流的起始位置为文件流的末尾

                        w.BaseStream.Seek(0, SeekOrigin.End);

                        ///写入当前系统时间并换行

                        m_nIndex += 1;

                        w.Write("{0}:{1}-{2}\n\r", DateTime.Now.ToString(),m_nIndex.ToString(), input);                     ///清空缓冲区内容,并把缓冲区内容写入基础流

                         w.Write("\r\n");

            w.Flush();

                        ///关闭写数据流

                        w.Close();

                    }

                }

                catch(Exception e )

                {

                        return ;

                 }

     }

    ----当EXTJS要调用是,在JS开头加上:

    function WriteLogFiles(input) {

        Ext.net.DirectMethods.WriteLogFile(input, {

            success: function (result) { 

     
            }
        });
    }


    需要调用的地方:WriteLogFiles("GetVehicleSimpleData Error:" + e.Message);         

  • 相关阅读:
    一周之内了解一个行业的方法
    du命令 实现Linux 某个文件夹下的文件按大小排序
    蝴蝶效应、青蛙现象、鳄鱼法则、鲇鱼效应.......
    MYSQ提高L查询效率的策略总结
    12个高矮不同的人,排成两排(catalan数)
    四人过桥、三盏灯 三个开关 的答案
    给定一个存放整数的数组,重新排列数组使得数组左边为奇数,右边为偶数。
    一个int 数组,里面数据无任何限制,要求求出所有这样的数a[i],其左边的数都小于等于它,右边的数都大于等于它。能否只用一个额外数组和少量其它空间实现。
    二分检索(查找)的各种变种
    排序算法稳定性
  • 原文地址:https://www.cnblogs.com/bingsying/p/7846658.html
Copyright © 2011-2022 走看看