This class accesses Windows event logs that are accessible through the Event Viewer administrative tool. Windows contains three logs by default: the Application Log, System Log, and Security Log. The Security Log is read-only, so you can't write events to it. Whenever you need to raise an event, you must select a system-wide unique event source. This source can be any keyword, as long as it is unique. To write an event to the Application log, use the static two-argument version of WriteEntry( ) , supplying the source name and message as string arguments. If the source does not exist, it is automatically registered. You can manually register a new event source several ways. First, call CreateEventSource( ) . If you do not specify a log name, then your events are registered with the generic Application Log. Otherwise, a new .evt file is created (in the %SystemRoot%\system32\config directory). Alternatively, create a new EventLog object, and set Source , Log , and MachineName to the appropriate values. To delete a source, call DeleteEventSource( ) . Delete( ) lets you delete an entire log, but be careful not to delete one of the Windows event logs! GetEventLogs( ) allows you to find the logs on the system, and LogNameFromSourceName( ) allows you to determine the log file for a given source. You can interact with a log in many ways. Add to it using WriteEntry( ) and remove all log entries by calling Clear( ) . Examine the Entries property to view the individual log entries. An EventLog can raise the EntryWritten event if you set EnableRaisingEvents to true . public class EventLog : System.ComponentModel.Component, System.ComponentModel.ISupportInitialize { // Public Constructors public EventLog ( ); public EventLog (string logName ); public EventLog (string logName , string machineName ); public EventLog (string logName , string machineName , string source ); // Public Instance Properties public bool EnableRaisingEvents {set; get; } public EventLogEntryCollection Entries {get; } public string Log {set; get; } public string LogDisplayName {get; } public string MachineName {set; get; } public string Source {set; get; } public ISynchronizeInvoke SynchronizingObject {set; get; } // Public Static Methods public static void CreateEventSource (string source , string logName ); public static void CreateEventSource (string source , string logName , string machineName ); public static void Delete (string logName ); public static void Delete (string logName , string machineName ); public static void DeleteEventSource (string source ); public static void DeleteEventSource (string source , string machineName ); public static bool Exists (string logName ); public static bool Exists (string logName , string machineName ); public static EventLog[ ] GetEventLogs ( ); public static EventLog[ ] GetEventLogs (string machineName ); public static string LogNameFromSourceName (string source , string machineName ); public static bool SourceExists (string source ); public static bool SourceExists (string source , string machineName ); public static void WriteEntry (string source , string message ); public static void WriteEntry (string source , string message , EventLogEntryType type ); public static void WriteEntry (string source , string message , EventLogEntryType type , int eventID ); public static void WriteEntry (string source , string message , EventLogEntryType type , int eventID , short category ); public static void WriteEntry (string source , string message , EventLogEntryType type , int eventID , short category , byte[ ] rawData ); // Public Instance Methods public void BeginInit ( ); // implements System.ComponentModel.ISupportInitialize public void Clear ( ); public void Close ( ); public void EndInit ( ); // implements System.ComponentModel.ISupportInitialize public void WriteEntry (string message ); public void WriteEntry (string message , EventLogEntryType type ); public void WriteEntry (string message , EventLogEntryType type , int eventID ); public void WriteEntry (string message , EventLogEntryType type , int eventID , short category ); public void WriteEntry (string message , EventLogEntryType type , int eventID , short category , byte[ ] rawData ); // Protected Instance Methods protected override void Dispose (bool disposing ); // overrides System.ComponentModel.Component // Events public event EntryWrittenEventHandler EntryWritten ; } HierarchySystem.Object System.MarshalByRefObject System.ComponentModel.Component(System.ComponentModel.IComponent, System.IDisposable) EventLog(System.ComponentModel.ISupportInitialize) Returned ByEventLogTraceListener.EventLog Passed ToEventLogTraceListener.{EventLog , EventLogTraceListener( )} |