另一個類可以直接輸出到系統事件日志:
class EventLogger
{
private static string eventSource;
private static EventLog logDest;
static EventLogger()
{
logger.Log +=new AddMessageEventHandler( Event_Log );
}
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;
}
}
private static void Event_Log( object sender,
LoggerEventArgs msg )
{
if ( logDest != null )
logDest.WriteEntry( msg.Message,
EventLogEntryType.Information,
msg.Priority );
}
}