---
title: "自己写的Log日志记录类，支持文件和数据库，自动建立Log表格"
author: "eicesoft"
date: "2007-09-12T15:58:00Z"
tags: []
slug: "log-log"
draft: false
lastmod: "2007-09-12T15:58:00Z"
id: 674958
url: "https://eicesoft.iteye.com/blog/674958"
---

自己写的 Log日志记录类，支持文件和数据库，自动建立Log表格，刚学设计模式，大家别见笑。

文件：ILog.cs代码

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)using System;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)namespace LZ2007.Function.Log  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)    /\*\*//// &lt;summary&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    /// 日志通用接口  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)    /// &lt;/summary&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    public interface ILog  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)    ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        void Info(string message, int level);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        void Info(string message);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        void Warn(string message, int leave);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        void Warn(string message);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        void Debug(string message, int leave);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        void Debug(string message);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        void Error(string message, Exception e, int leave);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        void Error(string message, Exception e);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        void Fatal(string message, Exception e, int leave);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        void Fatal(string message, Exception e);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        void Close();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)    }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}

文件LogManage.cs代码

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)using System;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)using System.Data;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)using System.Configuration;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)namespace LZ2007.Function.Log  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)    /\*\*//// &lt;summary&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    /// 日志工厂类  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)    /// &lt;/summary&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    public static class LogFactory  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)    ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        public static ILog GetLog(Type objType)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)        ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            int \_LogType = Convert.ToInt32(ConfigurationManager.AppSettings\["eLogType"]);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            ILog log = null;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            if (\_LogType == 1)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)            ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                log = new DataBaseLog(objType);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)            }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            else if(\_LogType==0)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)            ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                log = new FileLog(objType);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)            }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            return log;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)        }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)    }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}

文件DataBaseLog.cs代码

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)using System;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)using System.Data;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)using System.Configuration;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)using System.Web;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)using System.Data.SqlClient;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)namespace LZ2007.Function.Log  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)    /\*\*//// &lt;summary&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    /// 数据库日志类.  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)    /// &lt;/summary&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    public class DataBaseLog : ILog  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)    ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)        私有变量申明#region 私有变量申明  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        private string \_LogConnStr;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        private string \_LogObjectSource;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        private bool \_isDebug;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        private bool \_isInfo;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        private bool \_isError;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        private bool \_isWarn;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        private SqlConnection \_sqlConn;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        public bool IsDebug  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)        ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)            get ...{ return \_isDebug; }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)            set ...{ \_isDebug = value; }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)        }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        public bool IsInfo  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)        ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)            get ...{ return \_isInfo; }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)            set ...{ \_isInfo = value; }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)        }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        public bool IsError  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)        ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)            get ...{ return \_isError; }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)            set ...{ \_isError = value; }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)        }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        public bool IsWarn  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)        ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)            get ...{ return \_isWarn; }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)            set ...{ \_isWarn = value; }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)        }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)        #endregion  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        public DataBaseLog(Type objType)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)        ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            \_isDebug = Convert.ToBoolean(ConfigurationManager.AppSettings\["eLogDebug"]);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            \_isInfo = Convert.ToBoolean(ConfigurationManager.AppSettings\["eLogInfo"]);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            \_isError = Convert.ToBoolean(ConfigurationManager.AppSettings\["eLogError"]);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            \_isWarn = Convert.ToBoolean(ConfigurationManager.AppSettings\["eLogWarn"]);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            \_LogObjectSource = objType.FullName;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            //\_LogType = Convert.ToInt32(ConfigurationManager.AppSettings\["eLogType"]);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            \_LogConnStr = ConfigurationManager.AppSettings\["eLogConnStr"];  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            \_sqlConn = new SqlConnection(\_LogConnStr);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            Init();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)        }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        private void Init()  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)        ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            //检查是否有该表  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            string strTest = "select count(name)as a1 from sysobjects where id = object\_id(N’\[LOGSYSTEM]’) and OBJECTPROPERTY(id, N’IsUserTable’) = 1";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            //建立表  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            string strSQL = "CREATE TABLE \[dbo].\[LOGSYSTEM] (" +  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                                "\[lId] \[int] IDENTITY (1, 1) NOT NULL ," +  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                                "\[lMessage] \[nvarchar] (1000) COLLATE Chinese\_PRC\_CI\_AS NULL ," +  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                                "\[lLevel] \[int] NULL ," +  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                                "\[lSource] \[nvarchar] (100) COLLATE Chinese\_PRC\_CI\_AS NULL ," +  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                                "\[lException] \[nvarchar] (100) COLLATE Chinese\_PRC\_CI\_AS NULL ," +  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                                "\[lType] \[int] NULL ," +  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                                "\[lDate] \[datetime] NULL ," +  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                                "\[lADDIT1] \[nvarchar] (100) COLLATE Chinese\_PRC\_CI\_AS NULL ," +  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                                "\[lADDIT2] \[nvarchar] (100) COLLATE Chinese\_PRC\_CI\_AS NULL ," +  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                                "\[lADDIT3] \[nvarchar] (100) COLLATE Chinese\_PRC\_CI\_AS NULL " +  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                            ") ON \[PRIMARY]";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            \_sqlConn.Open();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            SqlCommand sqlcomm = new SqlCommand(strTest, \_sqlConn);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            int i = (int)sqlcomm.ExecuteScalar(); ;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            if (i == 0)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)            ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                sqlcomm = new SqlCommand(strSQL, \_sqlConn);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                sqlcomm.ExecuteNonQuery();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)            }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Dispose();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)        }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        private int insertLog(string message, int level, string source, string exception, int type)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)        ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            string strSQL = "INSERT INTO LOGSYSTEM(lMessage,lLevel,lSource,lException,lType,lDate) " +  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                "VALUES (@lMessage,@lLevel,@lSource,@lException,@lType,@lDate)";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            SqlCommand sqlcomm = new SqlCommand(strSQL, \_sqlConn);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            if (\_sqlConn.State == ConnectionState.Closed)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)            ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                \_sqlConn.Open();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)            }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters.Add("@lMessage", SqlDbType.NVarChar, 1000);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters\["@lMessage"].Direction = ParameterDirection.Input;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters\["@lMessage"].Value = message;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters.Add("@lLevel", SqlDbType.Int);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters\["@lLevel"].Direction = ParameterDirection.Input;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters\["@lLevel"].Value = level;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters.Add("@lSource", SqlDbType.NVarChar, 100);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters\["@lSource"].Direction = ParameterDirection.Input;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters\["@lSource"].Value = source;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters.Add("@lException", SqlDbType.NVarChar, 100);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters\["@lException"].Direction = ParameterDirection.Input;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters\["@lException"].Value = exception;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters.Add("@lType", SqlDbType.Int);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters\["@lType"].Direction = ParameterDirection.Input;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters\["@lType"].Value = type;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters.Add("@lDate", SqlDbType.DateTime);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters\["@lDate"].Direction = ParameterDirection.Input;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            sqlcomm.Parameters\["@lDate"].Value = DateTime.Now;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            return sqlcomm.ExecuteNonQuery();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)        }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)        public void Close()  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)        ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            this.Info("Log End", 5);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)            \_sqlConn.Close();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)        }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)