07.11.2014 Views

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

74<br />

<strong>Enterprise</strong> <strong>Library</strong> <strong>Test</strong> <strong>Guide</strong><br />

Code test case<br />

Verify that the application<br />

block uses WMI and the<br />

event log to monitor errors<br />

during exception handling<br />

operations when the WMI<br />

and event log are enabled.<br />

Implemented?<br />

Yes<br />

Feature that is implemented<br />

For example, the ExceptionPolicyEntry.Handle method<br />

calls the private method ExecuteHandlerChain to<br />

execute the exception handlers that are defined in the<br />

exception policy. If an exception occurs while the ExecuteHandlerChain<br />

method handles the exceptions, the<br />

FireExceptionHandlingErrorOccurred method notifies<br />

WMI and the event log. The FireExceptionHandlingErrorOccurred<br />

method sends the error message to the<br />

ExceptionHandlingFailureEvent WMI event and logs<br />

the error to the <strong>Enterprise</strong> <strong>Library</strong> Exception Handling<br />

event log. This is shown in the following code example.<br />

private Exception ExecuteHandlerChain(Excepti<br />

on ex, Guid handlingInstanceID)<br />

{<br />

try<br />

{<br />

…<br />

ex = handler.HandleException(ex, handlingInstanceID);<br />

}<br />

catch (…)<br />

{<br />

…<br />

InstrumentationProvider.FireExceptionHandlingErrorOccurred(…));<br />

…<br />

}<br />

The ExceptionHandlingInstrumentationProvider class<br />

fires the exceptionHandlingErrorOccured event. The<br />

ExceptionHandlingErrorOccured method consumes<br />

the event and notifies WMI and logs the exception<br />

to the event log. This is shown in the following code<br />

example.<br />

[InstrumentationConsumer("ExceptionHandlingEr<br />

rorOccurred")]<br />

public void ExceptionHandlingErrorOccurred(…)<br />

{<br />

if (EventLoggingEnabled)<br />

{<br />

…<br />

EventLog.WriteEntry(GetEventSourceName(),<br />

entryText, EventLogEntryType.Error);<br />

}<br />

if (WmiEnabled) ManagementInstrumentation.<br />

Fire(new ExceptionHandlingFailureEvent(instan<br />

ceName, e.Message));<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!