iT Synergy Blogs

Growing Innovation - Soluciones a problemas reales

  • Facebook
  • Instagram
  • LinkedIn
  • Phone
  • Twitter
  • YouTube

Copyright © 2026 · iT Synergy·

Exception Handling – Enterprise Library

February 20, 2013 By Jaime Alonso Páez torres Leave a Comment

Objetivo

Ofrecer una introducción al manejo de excepciones que se pueden presentar en una aplicación web e incluir su registro en el event viewer.

Prerrequisitos

  • Enterprise Library 5.0.
  • Visual Studio

Pasos

La versión de Enterprise Library que se uso es la 5.0

1. Instalar Enterprise Library 5.0.

2. Adicionar las referencias a los siguientes assemblies, en el proyecto web o proyecto de cara al usuario:

Microsoft.Practices.EnterpriseLibrary.Common, Microsoft.Practices.ServiceLocation, Microsoft.Practices.Unity, Microsoft.Practices.Unity.Interception, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Microsoft.Practices.EnterpriseLibrary.Logging

3. En el archivo web.config y dentro del elemento <configuration>, colocar las siguientes lineas que incluye el manejo de las excepciones y el logging de las mismas.

 

<configSections>
<section name=”loggingConfiguration” type=”Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ requirePermission=”true”/>
<section name=”exceptionHandling” type=”Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ requirePermission=”true”/>
</configSections>

<loggingConfiguration name=”Logging Application Block” tracingEnabled=”true” defaultCategory=”General” logWarningsWhenNoCategoriesMatch=”true”>
<listeners>
<add name=”FormatEventLog TraceListener” type=”Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ listenerDataType=”Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ source=”NombreDeAplicacion” formatter=”Text Formatter” log=”Application” machineName=””/>
</listeners>
<formatters>
<add type=”Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ template=”Timestamp: {timestamp}{newline}Message: {message}{newline}Category: {category}{newline}Priority: {priority}{newline}EventId: {eventid}{newline}Severity: {severity}{newline}Title: {title}{newline}Activity ID: {property(ActivityId)}{newline}Machine: {localMachine}{newline}App Domain: {localAppDomain}{newline}ProcessId: {localProcessId}{newline}Process Name: {localProcessName}{newline}Thread Name: {threadName}{newline}Win32 ThreadId:{win32ThreadId}{newline}Extended Properties: {dictionary({key} – {value}{newline})}” name=”Text Formatter”/>
</formatters>
<categorySources>
<add switchValue=”All” name=”General”>
<listeners>
<add name=”FormatEventLog TraceListener”/>
</listeners>
</add>
<add switchValue=”Error” name=”Exceptions”>
<listeners>
<add name=”FormatEventLog TraceListener”/>
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue=”All” name=”All Events”/>
<notProcessed switchValue=”All” name=”Unprocessed Category”/>
<errors switchValue=”All” name=”Logging Errors &amp; Warnings”>
<listeners>
<add name=”FormatEventLog TraceListener”/>
</listeners>
</errors>
</specialSources>
</loggingConfiguration>

 

<exceptionHandling>
<exceptionPolicies>
<add name=”ServiceLayerExceptionPolicy“>
<exceptionTypes>
<add name=”Exception” type=”System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ postHandlingAction=”NotifyRethrow”>
<exceptionHandlers>
<add name=”Logging Handler” type=”Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ logCategory=”Exceptions” eventId=”100″ severity=”Error” title=”TituloaVisualizarEnEventViewer” formatterType=”Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling” priority=”0″/>
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>

 

Las partes señaladas en color rojo, indican el nombre de la aplicación web, el nombre de la política de excepciones definida en el Enterprise Library y el titulo que recibirá los errores registrados en el event viewer.

4.  Para garantizar un manejo centralizado de errores,  se implementa el evento Application_Error del global.asax.cs

Filed Under: .NET

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Blog Authors

avatar for Marco Antonio Hernández PradoMarco Antonio Hernández Prado
avatar for Jaime Alonso Páez torresJaime Alonso Páez torres
avatar for Luis Carlos Bernal ÁvilaLuis Carlos Bernal Ávila
avatar for Ana María Orozco ZuluagaAna María Orozco Zuluaga
avatar for Juan Camilo Zapata MontúfarJuan Camilo Zapata Montúfar
avatar for Sonia Elizabeth Soriano ContrerasSonia Elizabeth Soriano Contreras
avatar for Diana Díaz GrijalbaDiana Díaz Grijalba
avatar for Carlos Alberto Rueda ValenzuelaCarlos Alberto Rueda Valenzuela
avatar for Bernardo Enrique Cardales AcuñaBernardo Enrique Cardales Acuña
avatar for Alexandra Bravo RestrepoAlexandra Bravo Restrepo
avatar for Juan Alberto Vélez CasadiegoJuan Alberto Vélez Casadiego
avatar for Jhon Jairo RodriguezJhon Jairo Rodriguez
avatar for Diana Paola Padilla BeltránDiana Paola Padilla Beltrán
avatar for Alejandro Garcia ForeroAlejandro Garcia Forero
avatar for Gustavo Adolfo Echeverry LópezGustavo Adolfo Echeverry López
avatar for Jesús Javier Hernández LópezJesús Javier Hernández López
avatar for Yully Arias CastilloYully Arias Castillo
avatar for Brayan RuizBrayan Ruiz
avatar for Carlos Andrés Vélez CasadiegoCarlos Andrés Vélez Casadiego
avatar for Odahir Rolando Salcedo TangarifeOdahir Rolando Salcedo Tangarife
avatar for Josué Leonardo Bohórquez MorenoJosué Leonardo Bohórquez Moreno
avatar for Natalia Zartha SuárezNatalia Zartha Suárez
avatar for Oscar Alberto Urrea MartinezOscar Alberto Urrea Martinez
avatar for Jimmy Quejada MenesesJimmy Quejada Meneses
avatar for Carolina Torres RodríguezCarolina Torres Rodríguez
avatar for Mario Andrés CortésMario Andrés Cortés
avatar for Juan Mauricio García TorresJuan Mauricio García Torres
avatar for Eric Yovanny Martinez GonzalezEric Yovanny Martinez Gonzalez

Categories

  • .NET (33)
  • Analysis Services (1)
  • ASP.NET MVC (2)
  • Azure (7)
  • BAM (9)
  • BAM PrimaryImport (3)
  • BigData (1)
  • BizTalk (77)
  • BizTalk 2010 configurations (57)
  • BizTalk Application (60)
  • BizTalk Services (13)
  • Business Intelligence (4)
  • Cloud (3)
  • CMD (1)
  • CodeSmith – NetTiers (2)
  • CommandPrompt (1)
  • CRM OptionSet mapping component (1)
  • Desarrollo de software (6)
  • develop (6)
  • developers (3)
  • DropBox (1)
  • Dynamics (1)
  • Enterprise Architect (1)
  • Entity Framework (1)
  • Errores BizTalk (2)
  • ESB (27)
  • ETL (1)
  • Event Viewer (1)
  • Excel Services (1)
  • Foreach loop container (1)
  • General (4)
  • Gerencia de Proyectos (2)
  • Google (1)
  • Grouped Slices (1)
  • Human Talent (1)
  • IIS (4)
  • Integración (6)
  • Integration Services (3)
  • KingswaySoft (1)
  • Lync (1)
  • MSE (13)
  • Office 365 (2)
  • Oracle Data Adapter (2)
  • Performance Point (4)
  • Picklist (1)
  • Pivot Table (1)
  • Procesos (1)
  • Pruebas (1)
  • Public Website (2)
  • Reports (1)
  • SCRUM (1)
  • SDK (2)
  • SEO (1)
  • Servicios (2)
  • Sharepoint (9)
  • SharePoint 2010 (10)
  • SharePoint 2013 (4)
  • SharePoint Online (2)
  • SharpBox (1)
  • Shortcuts (1)
  • Sin categoría (1)
  • SOA (50)
  • SQL (5)
  • SQL Server (3)
  • SQL Server Management Studio (1)
  • SSIS (3)
  • SSL (1)
  • SSO (1)
  • Tracking Profile Editor (2)
  • Twitter (1)
  • Uncategorized (1)
  • Virtual Network (2)
  • Visual Studio 11 (1)
  • Visual Studio 2010 (2)
  • Visual Studio Online (1)
  • VMware (2)
  • WCF (24)
  • Web (1)
  • Web Api (1)
  • Windows (5)
  • Windows 8 (11)
  • Windows Azure (2)
  • Windows Live Write (1)
  • Windows Phone (7)
  • Windows Phone 8 (1)
  • Windows Scheduler (1)
  • windows8 (2)
  • WindowsRT (3)
  • WP7 SDK (1)

Manage

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org