zoukankan      html  css  js  c++  java
  • .NET写日志-log

     /// <summary>
            /// 寫log add by Rain 做测试用
            /// </summary>
            /// <param name="Logmessage"></param>
            public void WriteLog(string Logmessage)
            {
                string logtime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                string logfilename = "AutoRejectServicelog" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
                //string savePath =System.Web.HttpContext.Current.Server.MapPath(@"log");
                //string savePath = AppDomain.CurrentDomain.BaseDirectory + @"log";
                string savePath = "C:\AutoReject\log";
                if (!System.IO.Directory.Exists(savePath))
                { //需要注意的是,需要对这个物理路径有足够的权限,否则会报错   
                    //另外,这个路径应该是在网站之下,而将网站部署在C盘却把上传文件保存在D盘
                    System.IO.Directory.CreateDirectory(savePath);
                }
                Logmessage = "記錄執行步驟信息:進入該事件時間:" + logtime + " " + "相關信息: " + Logmessage + " ";
                System.IO.StreamWriter fd = new System.IO.StreamWriter(savePath + "\" + logfilename, true, System.Text.Encoding.Default);
                fd.WriteLine(Logmessage);
                fd.Flush();
                fd.Close();
            }

            /// <summary>
            /// 寫log add by Rain 做测试用
            /// </summary>
            /// <param name="Logmessage"></param>
            public void WriteErrorLog(string Logmessage)
            {
                string logtime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                string logfilename = "AutoRejectServicelog" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
                //string savePath =System.Web.HttpContext.Current.Server.MapPath(@"log");
                //string savePath = AppDomain.CurrentDomain.BaseDirectory + @"log";
                string savePath = "C:\AutoReject\log";
                if (!System.IO.Directory.Exists(savePath))
                { //需要注意的是,需要对这个物理路径有足够的权限,否则会报错   
                    //另外,这个路径应该是在网站之下,而将网站部署在C盘却把上传文件保存在D盘
                    System.IO.Directory.CreateDirectory(savePath);
                }
                Logmessage = "系統發生錯誤,發生時間:" + logtime + " " + "錯誤信息: " + Logmessage + " ";
                System.IO.StreamWriter fd = new System.IO.StreamWriter(savePath + "\" + logfilename, true, System.Text.Encoding.Default);
                fd.WriteLine(Logmessage);
                fd.Flush();
                fd.Close();
            }

  • 相关阅读:
    精通CSS高级Web解决方案(第2版)——读书笔记
    MySQL的知识点总结(一)
    json深拷贝
    Typescript 从Array 继承时碰到的问题
    webpack 笔记
    JavaScript 高效代码
    编写更优雅的 JavaScript 代码
    JavaScript复杂判断优雅写法
    深入浅出Javascript事件循环机制
    关于面向对象封装的思考--持续更新
  • 原文地址:https://www.cnblogs.com/Chinarain/p/3821901.html
Copyright © 2011-2022 走看看