iT Synergy Blogs

Growing Innovation - Soluciones a problemas reales

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

Copyright © 2023 · iT Synergy·

Exception Handling – Enterprise Library
Exception Handling – Enterprise Library avatar

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 Tagged With: Enterprise Library 5.0, Exception Handling, Logging

Team


Marco
Antonio Hernández

Jaime
Alonso Páez

Luis
Carlos Bernal

Ana
María Orozco

Juan
Camilo Zapata

Carlos
Alberto Rueda

Sonia
Elizabeth Soriano

Diana
Díaz Grijalba

Bernardo
Enrique Cardales

Alexandra
Bravo Restrepo

Juan
Alberto Vélez

Diana
Paola Padilla

Jhon
Jairo Rodriguez

Yully
Arias Castillo

Carlos
Andrés Vélez

Brayan
Ruiz

Jesús
Javier Hernández

Alejandro
Garcia Forero

Gustavo
Adolfo Echeverry

Josué
Leonardo Bohórquez

Oscar
Alberto Urrea

Odahir
Rolando Salcedo

Jimmy
Quejada Meneses

Natalia
Zartha Suárez

Mario
Andrés Cortés

Eric
Yovanny Martinez

Carolina
Torres Rodríguez

Juan
Mauricio García

Tag Cloud

.NET (9) 940px (1) Analysis Services mdx (1) An attempt was made to load a program with an incorrect format. (1) ASP.NET MVC (1) Azure (3) Backup (1) BAM (7) BAM API (1) BAMTraceException (2) BI (3) BizTalk (24) Business Intelligence (6) C# (2) caracteristicas de publicacion (2) Content Editor (3) ESB (15) ESB Toolkit (3) General (4) habilitar caracteristicas (3) indexes (2) Integration Services (2) Master Page (3) MDX (2) MSE (11) net.tcp (2) Office 365 (2) Oracle (2) Performance Point (2) Public Website (2) Receive Location (2) SDK (2) Servicio Web (2) Sharepoint 2010 (2) SharePoint 2013 (4) SharePoint Online (2) SOA (8) Soap Fault (2) Sort Months MDX (2) SQL Server (2) Visual (2) Visual Studio 2010 (2) WCF (19) Windows (3) Windows 8 (17)

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