zoukankan      html  css  js  c++  java
  • 【学习笔记】开发编程之《日志篇》

    在项目正式上线后,如果出现错误,异常,崩溃等情况

    我们往往第一想到的事就是查看日志

    所以日志对于一个系统的维护是非常重要的

                                                                      ㅡㅡㅡㅡ园内大神《冰麟轻武

    下面就是我自己用的一个方法,感觉还行

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.IO;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace Maticsoft.Web
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            Maticsoft.BLL.lhzExcSQL lhz = new BLL.lhzExcSQL();
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    try
                    {
                        DataTable dt = lhz.GetTalbe("select * from ad");
                        dt.Rows[0]["math"].ToString();
                    }
                    catch (Exception ex)
                    {
                        WriteIn(Server.MapPath("log.txt"), DateTime.Now.ToString() + "返回结果" + ex.Message);
                    }
                }
            }
            //写入日志
            public bool WriteIn(string strFilepath, string strNeirong)
            {
                bool bol = false;
                if (!File.Exists(strFilepath))//检查文件是否存在
                {
                    FileStream fs = File.Create(strFilepath);
                    fs.Close();
                }
                //写入文本
                StreamWriter sr = new StreamWriter(strFilepath, true, System.Text.Encoding.UTF8);
                try
                {
                    sr.WriteLine(strNeirong);
                    sr.Close();
                    bol = true;
                }
                catch
                {
                    bol = false;
                }
                return bol;
            }
        }
    }

    如下是效果图:

     

  • 相关阅读:
    [Python] 网络
    [c++] 命令
    [DB] 关系型数据库
    [win] cmd 常用命令
    [linux] Git基本概念&操作
    [SQL] 常用命令
    redis(二十四):Redis分布式锁以及实现(python)
    redis(二十三):Redis 集群(proxy 型)二
    redis(二十二):Redis 集群(proxy 型)一
    redis(二十一):Redis 架构模式实现(哨兵)
  • 原文地址:https://www.cnblogs.com/kudsu/p/9157103.html
Copyright © 2011-2022 走看看