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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Test</strong>ing the Logging Application Block 93<br />

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

Verify that the<br />

application block<br />

uses WMI and<br />

the event log to<br />

monitor and record<br />

errors that occur<br />

during logging<br />

operations, if WMI<br />

and the event log<br />

are enabled.<br />

Yes<br />

If an error occurs while the application block logs an<br />

error message, the application block uses the instrumentation<br />

provider to log exceptions to WMI and to the event<br />

log. In addition, the LogWriter class logs an exception<br />

to the errors special trace source, if it is included in the<br />

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

example.<br />

private void ReportUnknownException(…)<br />

{<br />

try<br />

{<br />

…<br />

structureHolder.ErrorsTraceSource.TraceData(…);<br />

}<br />

catch (Exception ex)<br />

{<br />

instrumentationProvider.FireFailureLoggingErrorEvent(…);<br />

}<br />

}<br />

If the error cannot be logged to the errors special trace<br />

source, the LoggingInstrumentationProvider class raises<br />

the failureLoggingError event. The FailureLoggingError<br />

method consumes the event and logs the exception to<br />

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

code example.<br />

[InstrumentationConsumer("FailureLoggingError"<br />

)]<br />

public void FailureLoggingError(…)<br />

{<br />

if (WmiEnabled) ManagementInstrumentation.<br />

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

if (EventLoggingEnabled)<br />

{<br />

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

EventLogEntryType.Error);<br />

}<br />

}<br />

continued

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

Saved successfully!

Ooh no, something went wrong!