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.

60<br />

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

Code test case Implemented? Feature that is implemented<br />

Verify that the application<br />

block uses WMI and the event<br />

log to monitor errors during<br />

database operations when<br />

WMI and the event log are<br />

enabled.<br />

Yes<br />

For example, the Database.OpenConnection<br />

method uses WMI, the event log, and performance<br />

counters when the connection fails.<br />

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

protected DbConnection OpenConnection()<br />

{<br />

try<br />

{<br />

connection = CreateConnection();<br />

connection.Open();<br />

}<br />

catch (Exception e)<br />

{<br />

instrumentationProvider.FireConnectio<br />

nFailedEvent(ConnectionStringNoCreden<br />

tials, e);<br />

throw;<br />

}<br />

}<br />

The FireConnectionFailedEvent method<br />

raises the connectionFailed event. The ConnectionFailed<br />

method consumes this event<br />

and notifies WMI, logs the exception to the<br />

event log, and increments the Connections<br />

failed/sec performance counter. This is<br />

shown in the following code example.<br />

[InstrumentationConsumer("ConnectionF<br />

ailed")]<br />

public void ConnectionFailed(…)<br />

{<br />

if (PerformanceCountersEnabled) connectionFailedCounter.Increment();<br />

if (WmiEnabled) System.Management.<br />

Instrumentation.Instrumentation.<br />

Fire(new ConnectionFailedEvent(…);<br />

if (EventLoggingEnabled)<br />

{<br />

…<br />

EventLog.WriteEntry(GetEventSourceN<br />

ame(), entryText, EventLogEntryType.<br />

Error);<br />

}<br />

}

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

Saved successfully!

Ooh no, something went wrong!