Information Technology Reference
In-Depth Information
logger.Log += (sender, msg) =>
{
if (logDest != null )
logDest.WriteEntry(msg.Message,
EventLogEntryType .Information,
msg.Priority);
};
}
public static string EventSource
{
get { return eventSource; }
set
{
eventSource = value ;
if (! EventLog .SourceExists(eventSource))
EventLog .CreateEventSource(eventSource,
"ApplicationEventLogger" );
if (logDest != null )
logDest.Dispose();
logDest = new EventLog ();
logDest.Source = eventSource;
}
}
}
Events notify any number of interested clients that something happened.
The Logger class does not need any prior knowledge of which objects are
interested in logging events.
The Logger class contained only one event. There are classes (mostly Win-
dows controls) that have very large numbers of events. In those cases, the
idea of using one field per event might be unacceptable. In some cases,
only a small number of the defined events is actually used in any one appli-
cation. If you encounter that situation, you can modify the design to cre-
ate the event objects only when needed at runtime.
The core framework contains examples of how to do this in the Windows
control subsystem. To show you how, add subsystems to the Logger class.
 
Search WWH ::




Custom Search