首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

微软企业库5.0错误处理模块有关问题

2012-08-27 
微软企业库5.0异常处理模块问题在用配置工具的时候 配置 Exception Handling+Logging模块logging settings

微软企业库5.0异常处理模块问题
在用配置工具的时候 配置 Exception Handling+Logging模块

logging settings 中的 loggintg target listeners 选项中,配置CustomTraceListener 里面的 add from file 时候,我选中了自己写的类,为什么 选中后没有反映,列表里并没有出来!


这是我类的代码

C# code
using System;using System.Data;using System.Diagnostics;using System.Text;using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;using Microsoft.Practices.EnterpriseLibrary.Data;using Microsoft.Practices.EnterpriseLibrary.Logging;using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;using Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners;using System.Data.Common;namespace Helper{     [ConfigurationElementType(typeof(CustomTraceListenerData))]    public class ExceptionCustomerListener : CustomTraceListener    {        /// <summary>        /// 数据库连接        /// </summary>        private Database db;        public ExceptionCustomerListener ( )        {            db = DBHelper.CreateDataBase ( );        }        #region Overrides of TraceListener        public override void TraceData ( TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data )        {            if (this.Filter == null || this.Filter.ShouldTrace ( eventCache, source, eventType, id, null, null, data, null ))            {                if (data is LogEntry)                {                    ExecuteWriteLogSQL ( data as LogEntry );                }                else if (data is String)                {                    Write ( data );                }                else                {                    base.TraceData ( eventCache, source, eventType, id, data );                }            }        }        public override void Write ( string message )        {            String messing = Utils.GetBetweenString ( message, "Message :", "Source :", 9 );            string exceptionInfo = Utils.GetBetweenString ( message, "Stack Trace :", "Additional Info:", 13 );            StringBuilder sb = new StringBuilder ( );            sb.Append ( "insert into ExceptionLog values (" );            sb.Append ( "(SELECT   max(id)+1   FROM   ExceptionLog)," );            sb.Append ( "@Message" );            sb.Append ( "@LogDate" );            sb.Append ( "@ExceptionLevel" );            sb.Append ( "@Exception" );            DbCommand com = db.GetSqlStringCommand ( sb.ToString ( ) );            //添加参数            db.AddInParameter ( com, "@Message", DbType.String, messing );            db.AddInParameter ( com, "@LogDate", DbType.String, DateTime.Now );            db.AddInParameter ( com, "@ExceptionLevel", DbType.String, message );            db.AddInParameter ( com, "@Exception", DbType.String, exceptionInfo );            int x = db.ExecuteNonQuery ( com );        }        public override void WriteLine ( string message )        {            Write ( message );        }        #endregion        /// <summary>        /// 日志写入数据库        /// </summary>        /// <param name="log"></param>        private void ExecuteWriteLogSQL ( LogEntry log )        {            String messing = Utils.GetBetweenString ( log.Message, "Message :", "Source :", 9 );            string exceptionInfo = Utils.GetBetweenString ( log.Message, "Stack Trace :", "Additional Info:", 13 );            StringBuilder sb = new StringBuilder ( );            sb.Append ( "insert into ExceptionLog values (" );            sb.Append ( "(SELECT   max(id)+1   FROM   ExceptionLog)," );            sb.Append ( "@Message" );            sb.Append ( "@LogDate" );            sb.Append ( "@ExceptionLevel" );            sb.Append ( "@Exception" );            DbCommand com = db.GetSqlStringCommand ( sb.ToString ( ) );            //添加参数            db.AddInParameter ( com, "@Message", DbType.String, messing );            db.AddInParameter ( com, "@LogDate", DbType.String, log.TimeStamp );            db.AddInParameter ( com, "@ExceptionLevel", DbType.String, log.LoggedSeverity );            db.AddInParameter ( com, "@Exception", DbType.String, exceptionInfo );            int x = db.ExecuteNonQuery ( com );        }    }} 



[解决办法]
帮楼主顶下。求知道。

热点排行