Enterprise library exception block RRS feed

  • Question

  • User-115257982 posted

    Hi experts,

    I am developing an application in two database Oracle & Sql Server, but i want to implement common Exception Handling for both dbs using Enterprise library

    please suggest me if possible


    Thanks in advance

    Wednesday, September 8, 2010 6:41 AM


All replies

  • User1414178881 posted

    Yes it's possible,maybe you can take a look at this article:


    You may take a look at section "DataAccessExceptionHandler" in that article.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 15, 2010 2:58 AM
  • User-115257982 posted

    already..i went through this url,

    I am able to log the exception to the SqlDatabase, but unbale to the Oracle 

    here is my code..plz help

    public class CustomFormateLogger
            private const string ErrorCategory = "Errors";// I have only one message category: Errors 
            public CustomFormateDBTraceListners()
                //TO DO:
            public static LogWriter GetLogWriter(Database  _dbBase)
                TextFormatter _formatter = new TextFormatter("Timestamp: {timestamp}{newline}" +
                                                          "Message: {message}{newline}" +
                                                          "Category: {category}{newline}");
                //DBCommonFactory _dbCFactory = new DBCommonFactory(_connString);
                LogSource emptyTraceSource = new LogSource("none");
                LogSource errorsTraceSource = new LogSource(ErrorCategory, System.Diagnostics.SourceLevels.All);
                errorsTraceSource.Listeners.Add(new FormattedDatabaseTraceListener(_dbBase, Constatns._writeLogProceName, Constatns._addCategoryProcName, _formatter));
                //List the Logsource details
                IDictionary<string, LogSource> traceSources = new Dictionary<string, LogSource>();
                traceSources.Add(errorsTraceSource.Name, errorsTraceSource);
                return new LogWriter(new ILogFilter[0], // ICollection<ILogFilter> filters
                                traceSources,        // IDictionary<string, LogSource> traceSources
                                emptyTraceSource,    // LogSource allEventsTraceSource
                                emptyTraceSource,    // LogSource notProcessedTraceSource
                                errorsTraceSource,    // LogSource errorsTraceSource
                                ErrorCategory,        // string defaultCategory
                                false,                // bool tracingEnabled
                                true);                // bool logWarningsWhenNoCategoriesMatch
     public class CustomExceptionPolicy
            private static LogWriter writer = null;
            public static void HandleException(Exception exception,string _conneString )
                Database _dbBase = DBFactory.CustomDataBase.CreateDataBase(_conneString);
                writer = CustomFormateDBTraceListners.GetLogWriter(_dbBase);
                LogEntry exEntry = new LogEntry();
                exEntry.EventId = 100;
                exEntry.Message = exception.Message;
                //System.Configuration.ConfigurationManager.AppSettings["error"] = ex.Message;
                exEntry.Priority = 1;
                exEntry.Severity = System.Diagnostics.TraceEventType.Error;
                exEntry.TimeStamp = System.DateTime.Now;
                exEntry.Title = HttpContext.Current.Request.RawUrl;
    & in my aspx page...im calling the exception like
                    int a = 10, b = 0;
                    b = a / b;
                catch (Exception ex)
    here ConnectionString is my database connection name


    Wednesday, September 15, 2010 3:29 AM
  • User1414178881 posted

    Can you post your webconfig?

    Wednesday, September 15, 2010 6:19 AM
  • User-115257982 posted

    Thanks for ur reply.

    i didnt config anything in my web.config file except the connection string.

    Based on the Connection Name it is creating the Database name instance

    even if config the web.config file exception is not logging to the database

    already i posted my web.config file, please go through this



    Wednesday, September 15, 2010 6:23 AM
  • User1414178881 posted

    It seems to me that your webconfig has no issues,Would you check out this article:


    Thursday, September 16, 2010 4:37 AM