我编了个小软件,想在软件中添加记录操作软件的日志功能,把用户的一些操作都记录在日志里.比如,软件中有个数据库的删除操作,当用户删除某条数据库的数据时,把这个事件记录在日志中.
请问各位大虾,如何编写日志功能,如何将操作记录在日志中呢?

解决方案 »

  1.   

    把所有的按钮,菜单等重写,后缀加入一个写log的功能操作
      

  2.   

    如果你的软件本身就操作数据库 那么可以在数据库中加一个日志表
    没操作数据库可以直接写log.txt文件或.xml文件数据
    定义个操作枚举类型
        public enum UserAction
        {
            actLogIn = 1,
            actLogOut = 2,
            actCreate = 3,
            actUpdate = 4,
            actDelete = 5,
            actView = 6,
            actQuote = 7,
        }
    再你执行操作的地方
    例如删除操作
     ActiveLogBE log = new ActiveLogBE();
            log.UserID = user.UserID;
            log.UserName = user.TrueName;
            log.WebPage = Request.Url.ToString();
            log.ActionTypeID = (byte)UserAction.actDelete;
            log.Description = "作废合同信息";string outMSG = string.Empty;
            if (new GaoMai.BLL.Contract().Delete(Convert.ToInt32(i), out outMSG))
            {
                log.Issuccessed = 1;
                if (Application["ActLogEnabled"].ToString() == "1")
                {
                    new GaoMai.BLL.ActiveLog().Add(log);
                }
                Common.WriteAlert(outMSG, "Contract.aspx");
            }
            else
            {
                log.Issuccessed = 0;
                if (Application["ActLogEnabled"].ToString() == "1")
                {
                    new GaoMai.BLL.ActiveLog().Add(log);
                }
                Common.WriteAlert(outMSG, "Contract.aspx");
            }
      

  3.   

    你可以自己手动写操作日志,就是谁在什么时候干了些什么,你可以保存成text,xml等格式,还有一种方法就是用.net自己的日志类,把日志写进windows的系统日志中,你可以看看msdn中关于日志类的使用方法。
      

  4.   

    自己写日志了,把你想记录的用户操作写入Txt 文件。