mscorlib(4.0.0.0) API with additions
System.Diagnostics.EventLog Class Reference

Provides interaction with Windows event logs. More...

Inheritance diagram for System.Diagnostics.EventLog:
[legend]
Collaboration diagram for System.Diagnostics.EventLog:
[legend]

Public Member Functions

 EventLog ()
 Initializes a new instance of the T:System.Diagnostics.EventLog class. Does not associate the instance with any log. More...
 
 EventLog (string logName)
 Initializes a new instance of the T:System.Diagnostics.EventLog class. Associates the instance with a log on the local computer. More...
 
 EventLog (string logName, string machineName)
 Initializes a new instance of the T:System.Diagnostics.EventLog class. Associates the instance with a log on the specified computer. More...
 
 EventLog (string logName, string machineName, string source)
 Initializes a new instance of the T:System.Diagnostics.EventLog class. Associates the instance with a log on the specified computer and creates or assigns the specified source to the T:System.Diagnostics.EventLog. More...
 
void BeginInit ()
 Begins the initialization of an T:System.Diagnostics.EventLog used on a form or used by another component. The initialization occurs at runtime. More...
 
void Clear ()
 Removes all entries from the event log. More...
 
void Close ()
 Closes the event log and releases read and write handles. More...
 
void EndInit ()
 Ends the initialization of an T:System.Diagnostics.EventLog used on a form or by another component. The initialization occurs at runtime. More...
 
void ModifyOverflowPolicy (OverflowAction action, int retentionDays)
 Changes the configured behavior for writing new entries when the event log reaches its maximum file size. More...
 
void RegisterDisplayName (string resourceFile, long resourceId)
 Specifies the localized name of the event log, which is displayed in the server Event Viewer. More...
 
void WriteEntry (string message)
 Writes an information type entry, with the given message text, to the event log. More...
 
void WriteEntry (string message, EventLogEntryType type)
 Writes an error, warning, information, success audit, or failure audit entry with the given message text to the event log. More...
 
void WriteEntry (string message, EventLogEntryType type, int eventID)
 Writes an entry with the given message text and application-defined event identifier to the event log. More...
 
void WriteEntry (string message, EventLogEntryType type, int eventID, short category)
 Writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log. More...
 
void WriteEntry (string message, EventLogEntryType type, int eventID, short category, byte[] rawData)
 Writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log, and appends binary data to the message. More...
 
void WriteEvent (EventInstance instance, params object[] values)
 Writes a localized entry to the event log. More...
 
void WriteEvent (EventInstance instance, byte[] data, params object[] values)
 Writes an event log entry with the given event data, message replacement strings, and associated binary data. More...
 
- Public Member Functions inherited from System.ComponentModel.Component
void Dispose ()
 Releases all resources used by the T:System.ComponentModel.Component. More...
 
override string ToString ()
 Returns a T:System.String containing the name of the T:System.ComponentModel.Component, if any. This method should not be overridden. More...
 
- Public Member Functions inherited from System.MarshalByRefObject
object GetLifetimeService ()
 Retrieves the current lifetime service object that controls the lifetime policy for this instance. More...
 
virtual object InitializeLifetimeService ()
 Obtains a lifetime service object to control the lifetime policy for this instance. More...
 
virtual ObjRef CreateObjRef (Type requestedType)
 Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. More...
 

Static Public Member Functions

static void CreateEventSource (string source, string logName)
 Establishes the specified source name as a valid event source for writing entries to a log on the local computer. This method can also create a new custom log on the local computer. More...
 
static void CreateEventSource (string source, string logName, string machineName)
 Establishes the specified source name as a valid event source for writing entries to a log on the specified computer. This method can also be used to create a new custom log on the specified computer. More...
 
static void CreateEventSource (EventSourceCreationData sourceData)
 Establishes a valid event source for writing localized event messages, using the specified configuration properties for the event source and the corresponding event log. More...
 
static void Delete (string logName)
 Removes an event log from the local computer. More...
 
static void Delete (string logName, string machineName)
 Removes an event log from the specified computer. More...
 
static void DeleteEventSource (string source)
 Removes the event source registration from the event log of the local computer. More...
 
static void DeleteEventSource (string source, string machineName)
 Removes the application's event source registration from the specified computer. More...
 
static bool Exists (string logName)
 Determines whether the log exists on the local computer. More...
 
static bool Exists (string logName, string machineName)
 Determines whether the log exists on the specified computer. More...
 
static EventLog [] GetEventLogs ()
 Searches for all event logs on the local computer and creates an array of T:System.Diagnostics.EventLog objects that contain the list. More...
 
static EventLog [] GetEventLogs (string machineName)
 Searches for all event logs on the given computer and creates an array of T:System.Diagnostics.EventLog objects that contain the list. More...
 
static bool SourceExists (string source)
 Determines whether an event source is registered on the local computer. More...
 
static bool SourceExists (string source, string machineName)
 Determines whether an event source is registered on a specified computer. More...
 
static string LogNameFromSourceName (string source, string machineName)
 Gets the name of the log to which the specified source is registered. More...
 
static void WriteEntry (string source, string message)
 Writes an information type entry with the given message text to the event log, using the specified registered event source. More...
 
static void WriteEntry (string source, string message, EventLogEntryType type)
 Writes an error, warning, information, success audit, or failure audit entry with the given message text to the event log, using the specified registered event source. More...
 
static void WriteEntry (string source, string message, EventLogEntryType type, int eventID)
 Writes an entry with the given message text and application-defined event identifier to the event log, using the specified registered event source. More...
 
static void WriteEntry (string source, string message, EventLogEntryType type, int eventID, short category)
 Writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log, using the specified registered event source. The category can be used by the Event Viewer to filter events in the log. More...
 
static void WriteEntry (string source, string message, EventLogEntryType type, int eventID, short category, byte[] rawData)
 Writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log (using the specified registered event source) and appends binary data to the message. More...
 
static void WriteEvent (string source, EventInstance instance, params object[] values)
 Writes an event log entry with the given event data and message replacement strings, using the specified registered event source. More...
 
static void WriteEvent (string source, EventInstance instance, byte[] data, params object[] values)
 Writes an event log entry with the given event data, message replacement strings, and associated binary data, and using the specified registered event source. More...
 

Protected Member Functions

override void Dispose (bool disposing)
 Releases the unmanaged resources used by the T:System.Diagnostics.EventLog, and optionally releases the managed resources. More...
 
- Protected Member Functions inherited from System.ComponentModel.Component
virtual object GetService (Type service)
 Returns an object that represents a service provided by the T:System.ComponentModel.Component or by its T:System.ComponentModel.Container. More...
 
- Protected Member Functions inherited from System.MarshalByRefObject
MarshalByRefObject MemberwiseClone (bool cloneIdentity)
 Creates a shallow copy of the current T:System.MarshalByRefObject object. More...
 

Properties

EventLogEntryCollection Entries [get]
 Gets the contents of the event log. More...
 
string LogDisplayName [get]
 Gets the event log's friendly name. More...
 
string Log [get, set]
 Gets or sets the name of the log to read from or write to. More...
 
string MachineName [get, set]
 Gets or sets the name of the computer on which to read or write events. More...
 
long MaximumKilobytes [get, set]
 Gets or sets the maximum event log size in kilobytes. More...
 
OverflowAction OverflowAction [get]
 Gets the configured behavior for storing new entries when the event log reaches its maximum log file size. More...
 
int MinimumRetentionDays [get]
 Gets the number of days to retain entries in the event log. More...
 
bool EnableRaisingEvents [get, set]
 Gets or sets a value indicating whether the T:System.Diagnostics.EventLog receives E:System.Diagnostics.EventLog.EntryWritten event notifications. More...
 
ISynchronizeInvoke SynchronizingObject [get, set]
 Gets or sets the object used to marshal the event handler calls issued as a result of an T:System.Diagnostics.EventLog entry written event. More...
 
string Source [get, set]
 Gets or sets the source name to register and use when writing to the event log. More...
 
EntryWrittenEventHandler EntryWritten
 Occurs when an entry is written to an event log on the local computer. More...
 
- Properties inherited from System.ComponentModel.Component
EventHandlerList Events [get]
 Gets the list of event handlers that are attached to this T:System.ComponentModel.Component. More...
 
virtual ISite Site [get, set]
 Gets or sets the T:System.ComponentModel.ISite of the T:System.ComponentModel.Component. More...
 
IContainerContainer [get]
 Gets the T:System.ComponentModel.IContainer that contains the T:System.ComponentModel.Component. More...
 
bool??? DesignMode [get]
 Gets a value that indicates whether the T:System.ComponentModel.Component is currently in design mode. More...
 
EventHandler Disposed
 Occurs when the component is disposed by a call to the M:System.ComponentModel.Component.Dispose method. More...
 
- Properties inherited from System.ComponentModel.IComponent
ISite Site [get, set]
 Gets or sets the T:System.ComponentModel.ISite associated with the T:System.ComponentModel.IComponent. More...
 

Additional Inherited Members

- Protected Attributes inherited from System.ComponentModel.Component
virtual bool CanRaiseEvents => true
 Gets a value indicating whether the component can raise an event. More...
 
- Events inherited from System.ComponentModel.IComponent
EventHandler Disposed
 Represents the method that handles the E:System.ComponentModel.IComponent.Disposed event of a component. More...
 

Detailed Description

Provides interaction with Windows event logs.

Definition at line 20 of file EventLog.cs.

Constructor & Destructor Documentation

◆ EventLog() [1/4]

System.Diagnostics.EventLog.EventLog ( )

Initializes a new instance of the T:System.Diagnostics.EventLog class. Does not associate the instance with any log.

Definition at line 273 of file EventLog.cs.

◆ EventLog() [2/4]

System.Diagnostics.EventLog.EventLog ( string  logName)

Initializes a new instance of the T:System.Diagnostics.EventLog class. Associates the instance with a log on the local computer.

Parameters
logNameThe name of the log on the local computer.
Exceptions
T:System.ArgumentNullExceptionThe log name is null.
T:System.ArgumentExceptionThe log name is invalid.

Definition at line 282 of file EventLog.cs.

◆ EventLog() [3/4]

System.Diagnostics.EventLog.EventLog ( string  logName,
string  machineName 
)

Initializes a new instance of the T:System.Diagnostics.EventLog class. Associates the instance with a log on the specified computer.

Parameters
logNameThe name of the log on the specified computer.
machineNameThe computer on which the log exists.
Exceptions
T:System.ArgumentNullExceptionThe log name is null.
T:System.ArgumentExceptionThe log name is invalid.-or- The computer name is invalid.

Definition at line 292 of file EventLog.cs.

◆ EventLog() [4/4]

System.Diagnostics.EventLog.EventLog ( string  logName,
string  machineName,
string  source 
)

Initializes a new instance of the T:System.Diagnostics.EventLog class. Associates the instance with a log on the specified computer and creates or assigns the specified source to the T:System.Diagnostics.EventLog.

Parameters
logNameThe name of the log on the specified computer
machineNameThe computer on which the log exists.
sourceThe source of event log entries.
Exceptions
T:System.ArgumentNullExceptionThe log name is null.
T:System.ArgumentExceptionThe log name is invalid.-or- The computer name is invalid.

Definition at line 303 of file EventLog.cs.

Member Function Documentation

◆ BeginInit()

void System.Diagnostics.EventLog.BeginInit ( )

Begins the initialization of an T:System.Diagnostics.EventLog used on a form or used by another component. The initialization occurs at runtime.

Exceptions
T:System.InvalidOperationExceptionT:System.Diagnostics.EventLog is already initialized.

Implements System.ComponentModel.ISupportInitialize.

Definition at line 316 of file EventLog.cs.

◆ Clear()

void System.Diagnostics.EventLog.Clear ( )

Removes all entries from the event log.

Exceptions
T:System.ComponentModel.Win32ExceptionThe event log was not cleared successfully.-or- The log cannot be opened. A Windows error code is not available.
T:System.ArgumentExceptionA value is not specified for the P:System.Diagnostics.EventLog.Log property. Make sure the log name is not an empty string.
T:System.InvalidOperationExceptionThe log does not exist.

Definition at line 325 of file EventLog.cs.

◆ Close()

void System.Diagnostics.EventLog.Close ( )

Closes the event log and releases read and write handles.

Exceptions
T:System.ComponentModel.Win32ExceptionThe event log's read handle or write handle was not released successfully.

Definition at line 332 of file EventLog.cs.

◆ CreateEventSource() [1/3]

static void System.Diagnostics.EventLog.CreateEventSource ( string  source,
string  logName 
)
static

Establishes the specified source name as a valid event source for writing entries to a log on the local computer. This method can also create a new custom log on the local computer.

Parameters
sourceThe source name by which the application is registered on the local computer.
logNameThe name of the log the source's entries are written to. Possible values include Application, System, or a custom event log.
Exceptions
T:System.ArgumentExceptionsource is an empty string ("") or null.- or - logName is not a valid event log name. Event log names must consist of printable characters, and cannot include the characters '*', '?', or '\'.- or - logName is not valid for user log creation. The event log names AppEvent, SysEvent, and SecEvent are reserved for system use.- or - The log name matches an existing event source name.- or - The source name results in a registry key path longer than 254 characters.- or - The first 8 characters of logName match the first 8 characters of an existing event log name.- or - The source cannot be registered because it already exists on the local computer.- or - The source name matches an existing event log name.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened on the local computer.

Definition at line 345 of file EventLog.cs.

◆ CreateEventSource() [2/3]

static void System.Diagnostics.EventLog.CreateEventSource ( string  source,
string  logName,
string  machineName 
)
static

Establishes the specified source name as a valid event source for writing entries to a log on the specified computer. This method can also be used to create a new custom log on the specified computer.

Parameters
sourceThe source by which the application is registered on the specified computer.
logNameThe name of the log the source's entries are written to. Possible values include Application, System, or a custom event log. If you do not specify a value, logName defaults to Application.
machineNameThe name of the computer to register this event source with, or "." for the local computer.
Exceptions
T:System.ArgumentExceptionThe machineName is not a valid computer name.- or - source is an empty string ("") or null.- or - logName is not a valid event log name. Event log names must consist of printable characters, and cannot include the characters '*', '?', or '\'.- or - logName is not valid for user log creation. The event log names AppEvent, SysEvent, and SecEvent are reserved for system use.- or - The log name matches an existing event source name.- or - The source name results in a registry key path longer than 254 characters.- or - The first 8 characters of logName match the first 8 characters of an existing event log name on the specified computer.- or - The source cannot be registered because it already exists on the specified computer.- or - The source name matches an existing event source name.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened on the specified computer.

Definition at line 360 of file EventLog.cs.

◆ CreateEventSource() [3/3]

static void System.Diagnostics.EventLog.CreateEventSource ( EventSourceCreationData  sourceData)
static

Establishes a valid event source for writing localized event messages, using the specified configuration properties for the event source and the corresponding event log.

Parameters
sourceDataThe configuration properties for the event source and its target event log.
Exceptions
T:System.ArgumentExceptionThe computer name specified in sourceData is not valid.- or - The source name specified in sourceData is null.- or - The log name specified in sourceData is not valid. Event log names must consist of printable characters and cannot include the characters '*', '?', or '\'.- or - The log name specified in sourceData is not valid for user log creation. The Event log names AppEvent, SysEvent, and SecEvent are reserved for system use.- or - The log name matches an existing event source name.- or - The source name specified in sourceData results in a registry key path longer than 254 characters.- or - The first 8 characters of the log name specified in sourceData are not unique.- or - The source name specified in sourceData is already registered.- or - The source name specified in sourceData matches an existing event log name.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened.
T:System.ArgumentNullExceptionsourceData is null.

Definition at line 371 of file EventLog.cs.

◆ Delete() [1/2]

static void System.Diagnostics.EventLog.Delete ( string  logName)
static

Removes an event log from the local computer.

Parameters
logNameThe name of the log to delete. Possible values include: Application, Security, System, and any custom event logs on the computer.
Exceptions
T:System.ArgumentExceptionlogName is an empty string ("") or null.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened on the local computer.- or - The log does not exist on the local computer.
T:System.ComponentModel.Win32ExceptionThe event log was not cleared successfully.-or- The log cannot be opened. A Windows error code is not available.

Definition at line 539 of file EventLog.cs.

◆ Delete() [2/2]

static void System.Diagnostics.EventLog.Delete ( string  logName,
string  machineName 
)
static

Removes an event log from the specified computer.

Parameters
logNameThe name of the log to delete. Possible values include: Application, Security, System, and any custom event logs on the specified computer.
machineNameThe name of the computer to delete the log from, or "." for the local computer.
Exceptions
T:System.ArgumentExceptionlogName is an empty string ("") or null. - or - machineName is not a valid computer name.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened on the specified computer.- or - The log does not exist on the specified computer.
T:System.ComponentModel.Win32ExceptionThe event log was not cleared successfully.-or- The log cannot be opened. A Windows error code is not available.

Definition at line 552 of file EventLog.cs.

◆ DeleteEventSource() [1/2]

static void System.Diagnostics.EventLog.DeleteEventSource ( string  source)
static

Removes the event source registration from the event log of the local computer.

Parameters
sourceThe name by which the application is registered in the event log system.
Exceptions
T:System.ArgumentExceptionThe source parameter does not exist in the registry of the local computer.- or - You do not have write access on the registry key for the event log.

Definition at line 635 of file EventLog.cs.

◆ DeleteEventSource() [2/2]

static void System.Diagnostics.EventLog.DeleteEventSource ( string  source,
string  machineName 
)
static

Removes the application's event source registration from the specified computer.

Parameters
sourceThe name by which the application is registered in the event log system.
machineNameThe name of the computer to remove the registration from, or "." for the local computer.
Exceptions
T:System.ArgumentExceptionThe machineName parameter is invalid. - or - The source parameter does not exist in the registry of the specified computer.- or - You do not have write access on the registry key for the event log.
T:System.InvalidOperationExceptionsource cannot be deleted because in the registry, the parent registry key for source does not contain a subkey with the same name.

Definition at line 646 of file EventLog.cs.

◆ Dispose()

override void System.Diagnostics.EventLog.Dispose ( bool  disposing)
protectedvirtual

Releases the unmanaged resources used by the T:System.Diagnostics.EventLog, and optionally releases the managed resources.

Parameters
disposingtrue to release both managed and unmanaged resources; false to release only unmanaged resources.

Reimplemented from System.ComponentModel.Component.

Definition at line 719 of file EventLog.cs.

◆ EndInit()

void System.Diagnostics.EventLog.EndInit ( )

Ends the initialization of an T:System.Diagnostics.EventLog used on a form or by another component. The initialization occurs at runtime.

Implements System.ComponentModel.ISupportInitialize.

Definition at line 729 of file EventLog.cs.

◆ Exists() [1/2]

static bool System.Diagnostics.EventLog.Exists ( string  logName)
static

Determines whether the log exists on the local computer.

Parameters
logNameThe name of the log to search for. Possible values include: Application, Security, System, other application-specific logs (such as those associated with Active Directory), or any custom log on the computer.
Returns
true if the log exists on the local computer; otherwise, false.
Exceptions
T:System.ArgumentExceptionThe logName is null or the value is empty.

Definition at line 739 of file EventLog.cs.

◆ Exists() [2/2]

static bool System.Diagnostics.EventLog.Exists ( string  logName,
string  machineName 
)
static

Determines whether the log exists on the specified computer.

Parameters
logNameThe log for which to search. Possible values include: Application, Security, System, other application-specific logs (such as those associated with Active Directory), or any custom log on the computer.
machineNameThe name of the computer on which to search for the log, or "." for the local computer.
Returns
true if the log exists on the specified computer; otherwise, false.
Exceptions
T:System.ArgumentExceptionThe machineName parameter is an invalid format. Make sure you have used proper syntax for the computer on which you are searching.-or- The logName is null or the value is empty.

Definition at line 750 of file EventLog.cs.

◆ GetEventLogs() [1/2]

static EventLog [] System.Diagnostics.EventLog.GetEventLogs ( )
static

Searches for all event logs on the local computer and creates an array of T:System.Diagnostics.EventLog objects that contain the list.

Returns
An array of type T:System.Diagnostics.EventLog that represents the logs on the local computer.
Exceptions
T:System.SystemExceptionYou do not have read access to the registry.-or- There is no event log service on the computer.

Definition at line 883 of file EventLog.cs.

◆ GetEventLogs() [2/2]

static EventLog [] System.Diagnostics.EventLog.GetEventLogs ( string  machineName)
static

Searches for all event logs on the given computer and creates an array of T:System.Diagnostics.EventLog objects that contain the list.

Parameters
machineNameThe computer on which to search for event logs.
Returns
An array of type T:System.Diagnostics.EventLog that represents the logs on the given computer.
Exceptions
T:System.ArgumentExceptionThe machineName parameter is an invalid computer name.
T:System.InvalidOperationExceptionYou do not have read access to the registry.-or- There is no event log service on the computer.

Definition at line 893 of file EventLog.cs.

◆ LogNameFromSourceName()

static string System.Diagnostics.EventLog.LogNameFromSourceName ( string  source,
string  machineName 
)
static

Gets the name of the log to which the specified source is registered.

Parameters
sourceThe name of the event source.
machineNameThe name of the computer on which to look, or "." for the local computer.
Returns
The name of the log associated with the specified source in the registry.

Definition at line 994 of file EventLog.cs.

◆ ModifyOverflowPolicy()

void System.Diagnostics.EventLog.ModifyOverflowPolicy ( OverflowAction  action,
int  retentionDays 
)

Changes the configured behavior for writing new entries when the event log reaches its maximum file size.

Parameters
actionThe overflow behavior for writing new entries to the event log.
retentionDaysThe minimum number of days each event log entry is retained. This parameter is used only if action is set to F:System.Diagnostics.OverflowAction.OverwriteOlder.
Exceptions
T:System.ComponentModel.InvalidEnumArgumentExceptionaction is not a valid P:System.Diagnostics.EventLog.OverflowAction value.
T:System.ArgumentOutOfRangeExceptionretentionDays is less than one, or larger than 365.
T:System.InvalidOperationExceptionThe P:System.Diagnostics.EventLog.Log value is not a valid log name.- or -The registry key for the event log could not be opened on the target computer.

Definition at line 1024 of file EventLog.cs.

◆ RegisterDisplayName()

void System.Diagnostics.EventLog.RegisterDisplayName ( string  resourceFile,
long  resourceId 
)

Specifies the localized name of the event log, which is displayed in the server Event Viewer.

Parameters
resourceFileThe fully specified path to a localized resource file.
resourceIdThe resource identifier that indexes a localized string within the resource file.
Exceptions
T:System.InvalidOperationExceptionThe P:System.Diagnostics.EventLog.Log value is not a valid log name.- or -The registry key for the event log could not be opened on the target computer.
T:System.ArgumentNullExceptionresourceFile is null.

Definition at line 1036 of file EventLog.cs.

◆ SourceExists() [1/2]

static bool System.Diagnostics.EventLog.SourceExists ( string  source)
static

Determines whether an event source is registered on the local computer.

Parameters
sourceThe name of the event source.
Returns
true if the event source is registered on the local computer; otherwise, false.
Exceptions
T:System.Security.SecurityExceptionsource was not found, but some or all of the event logs could not be searched.

Definition at line 957 of file EventLog.cs.

◆ SourceExists() [2/2]

static bool System.Diagnostics.EventLog.SourceExists ( string  source,
string  machineName 
)
static

Determines whether an event source is registered on a specified computer.

Parameters
sourceThe name of the event source.
machineNameThe name the computer on which to look, or "." for the local computer.
Returns
true if the event source is registered on the given computer; otherwise, false.
Exceptions
T:System.ArgumentExceptionmachineName is an invalid computer name.
T:System.Security.SecurityExceptionsource was not found, but some or all of the event logs could not be searched.

Definition at line 971 of file EventLog.cs.

◆ WriteEntry() [1/10]

void System.Diagnostics.EventLog.WriteEntry ( string  message)

Writes an information type entry, with the given message text, to the event log.

Parameters
messageThe string to write to the event log.
Exceptions
T:System.ArgumentExceptionThe P:System.Diagnostics.EventLog.Source property of the T:System.Diagnostics.EventLog has not been set.-or- The method attempted to register a new event source, but the computer name in P:System.Diagnostics.EventLog.MachineName is not valid.- or -The source is already registered for a different event log.- or -The message string is longer than 31,839 bytes (32,766 bytes on Windows operating systems before Windows Vista).- or -The source name results in a registry key path longer than 254 characters.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened.
T:System.ComponentModel.Win32ExceptionThe operating system reported an error when writing the event entry to the event log. A Windows error code is not available.

Definition at line 1232 of file EventLog.cs.

◆ WriteEntry() [2/10]

static void System.Diagnostics.EventLog.WriteEntry ( string  source,
string  message 
)
static

Writes an information type entry with the given message text to the event log, using the specified registered event source.

Parameters
sourceThe source by which the application is registered on the specified computer.
messageThe string to write to the event log.
Exceptions
T:System.ArgumentExceptionThe source value is an empty string ("").- or -The source value is null.- or -The message string is longer than 31,839 bytes (32,766 bytes on Windows operating systems before Windows Vista).- or -The source name results in a registry key path longer than 254 characters.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened.
T:System.ComponentModel.Win32ExceptionThe operating system reported an error when writing the event entry to the event log. A Windows error code is not available.

Definition at line 1243 of file EventLog.cs.

◆ WriteEntry() [3/10]

void System.Diagnostics.EventLog.WriteEntry ( string  message,
EventLogEntryType  type 
)

Writes an error, warning, information, success audit, or failure audit entry with the given message text to the event log.

Parameters
messageThe string to write to the event log.
typeOne of the T:System.Diagnostics.EventLogEntryType values.
Exceptions
T:System.ArgumentExceptionThe P:System.Diagnostics.EventLog.Source property of the T:System.Diagnostics.EventLog has not been set.-or- The method attempted to register a new event source, but the computer name in P:System.Diagnostics.EventLog.MachineName is not valid.- or -The source is already registered for a different event log.- or -The message string is longer than 31,839 bytes (32,766 bytes on Windows operating systems before Windows Vista).- or -The source name results in a registry key path longer than 254 characters.
T:System.ComponentModel.InvalidEnumArgumentExceptiontype is not a valid T:System.Diagnostics.EventLogEntryType.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened.
T:System.ComponentModel.Win32ExceptionThe operating system reported an error when writing the event entry to the event log. A Windows error code is not available.

Definition at line 1256 of file EventLog.cs.

◆ WriteEntry() [4/10]

static void System.Diagnostics.EventLog.WriteEntry ( string  source,
string  message,
EventLogEntryType  type 
)
static

Writes an error, warning, information, success audit, or failure audit entry with the given message text to the event log, using the specified registered event source.

Parameters
sourceThe source by which the application is registered on the specified computer.
messageThe string to write to the event log.
typeOne of the T:System.Diagnostics.EventLogEntryType values.
Exceptions
T:System.ArgumentExceptionThe source value is an empty string ("").- or -The source value is null.- or -The message string is longer than 31,839 bytes (32,766 bytes on Windows operating systems before Windows Vista).- or -The source name results in a registry key path longer than 254 characters.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened.
T:System.ComponentModel.InvalidEnumArgumentExceptiontype is not a valid T:System.Diagnostics.EventLogEntryType.
T:System.ComponentModel.Win32ExceptionThe operating system reported an error when writing the event entry to the event log. A Windows error code is not available.

Definition at line 1270 of file EventLog.cs.

◆ WriteEntry() [5/10]

void System.Diagnostics.EventLog.WriteEntry ( string  message,
EventLogEntryType  type,
int  eventID 
)

Writes an entry with the given message text and application-defined event identifier to the event log.

Parameters
messageThe string to write to the event log.
typeOne of the T:System.Diagnostics.EventLogEntryType values.
eventIDThe application-specific identifier for the event.
Exceptions
T:System.ArgumentExceptionThe P:System.Diagnostics.EventLog.Source property of the T:System.Diagnostics.EventLog has not been set.-or- The method attempted to register a new event source, but the computer name in P:System.Diagnostics.EventLog.MachineName is not valid.- or -The source is already registered for a different event log.- or - eventID is less than zero or greater than F:System.UInt16.MaxValue.- or -The message string is longer than 31,839 bytes (32,766 bytes on Windows operating systems before Windows Vista).- or -The source name results in a registry key path longer than 254 characters.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened.
T:System.ComponentModel.InvalidEnumArgumentExceptiontype is not a valid T:System.Diagnostics.EventLogEntryType.
T:System.ComponentModel.Win32ExceptionThe operating system reported an error when writing the event entry to the event log. A Windows error code is not available.

Definition at line 1285 of file EventLog.cs.

◆ WriteEntry() [6/10]

static void System.Diagnostics.EventLog.WriteEntry ( string  source,
string  message,
EventLogEntryType  type,
int  eventID 
)
static

Writes an entry with the given message text and application-defined event identifier to the event log, using the specified registered event source.

Parameters
sourceThe source by which the application is registered on the specified computer.
messageThe string to write to the event log.
typeOne of the T:System.Diagnostics.EventLogEntryType values.
eventIDThe application-specific identifier for the event.
Exceptions
T:System.ArgumentExceptionThe source value is an empty string ("").- or -The source value is null.- or - eventID is less than zero or greater than F:System.UInt16.MaxValue.- or -The message string is longer than 31,839 bytes (32,766 bytes on Windows operating systems before Windows Vista).- or -The source name results in a registry key path longer than 254 characters.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened.
T:System.ComponentModel.InvalidEnumArgumentExceptiontype is not a valid T:System.Diagnostics.EventLogEntryType.
T:System.ComponentModel.Win32ExceptionThe operating system reported an error when writing the event entry to the event log. A Windows error code is not available.

Definition at line 1301 of file EventLog.cs.

◆ WriteEntry() [7/10]

void System.Diagnostics.EventLog.WriteEntry ( string  message,
EventLogEntryType  type,
int  eventID,
short  category 
)

Writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log.

Parameters
messageThe string to write to the event log.
typeOne of the T:System.Diagnostics.EventLogEntryType values.
eventIDThe application-specific identifier for the event.
categoryThe application-specific subcategory associated with the message.
Exceptions
T:System.ArgumentExceptionThe P:System.Diagnostics.EventLog.Source property of the T:System.Diagnostics.EventLog has not been set.-or- The method attempted to register a new event source, but the computer name in P:System.Diagnostics.EventLog.MachineName is not valid.- or -The source is already registered for a different event log.- or - eventID is less than zero or greater than F:System.UInt16.MaxValue.- or -The message string is longer than 31,839 bytes (32,766 bytes on Windows operating systems before Windows Vista).- or -The source name results in a registry key path longer than 254 characters.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened.
T:System.ComponentModel.InvalidEnumArgumentExceptiontype is not a valid T:System.Diagnostics.EventLogEntryType.
T:System.ComponentModel.Win32ExceptionThe operating system reported an error when writing the event entry to the event log. A Windows error code is not available.

Definition at line 1317 of file EventLog.cs.

◆ WriteEntry() [8/10]

static void System.Diagnostics.EventLog.WriteEntry ( string  source,
string  message,
EventLogEntryType  type,
int  eventID,
short  category 
)
static

Writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log, using the specified registered event source. The category can be used by the Event Viewer to filter events in the log.

Parameters
sourceThe source by which the application is registered on the specified computer.
messageThe string to write to the event log.
typeOne of the T:System.Diagnostics.EventLogEntryType values.
eventIDThe application-specific identifier for the event.
categoryThe application-specific subcategory associated with the message.
Exceptions
T:System.ArgumentExceptionThe source value is an empty string ("").- or -The source value is null.- or - eventID is less than zero or greater than F:System.UInt16.MaxValue.- or -The message string is longer than 31,839 bytes (32,766 bytes on Windows operating systems before Windows Vista).- or -The source name results in a registry key path longer than 254 characters.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened.
T:System.ComponentModel.InvalidEnumArgumentExceptiontype is not a valid T:System.Diagnostics.EventLogEntryType.
T:System.ComponentModel.Win32ExceptionThe operating system reported an error when writing the event entry to the event log. A Windows error code is not available.

Definition at line 1334 of file EventLog.cs.

◆ WriteEntry() [9/10]

static void System.Diagnostics.EventLog.WriteEntry ( string  source,
string  message,
EventLogEntryType  type,
int  eventID,
short  category,
byte []  rawData 
)
static

Writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log (using the specified registered event source) and appends binary data to the message.

Parameters
sourceThe source by which the application is registered on the specified computer.
messageThe string to write to the event log.
typeOne of the T:System.Diagnostics.EventLogEntryType values.
eventIDThe application-specific identifier for the event.
categoryThe application-specific subcategory associated with the message.
rawDataAn array of bytes that holds the binary data associated with the entry.
Exceptions
T:System.ArgumentExceptionThe source value is an empty string ("").- or -The source value is null.- or - eventID is less than zero or greater than F:System.UInt16.MaxValue.- or -The message string is longer than 31,839 bytes (32,766 bytes on Windows operating systems before Windows Vista).- or -The source name results in a registry key path longer than 254 characters.
T:System.ComponentModel.InvalidEnumArgumentExceptiontype is not a valid T:System.Diagnostics.EventLogEntryType.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened.
T:System.ComponentModel.Win32ExceptionThe operating system reported an error when writing the event entry to the event log. A Windows error code is not available.

Definition at line 1352 of file EventLog.cs.

◆ WriteEntry() [10/10]

void System.Diagnostics.EventLog.WriteEntry ( string  message,
EventLogEntryType  type,
int  eventID,
short  category,
byte []  rawData 
)

Writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log, and appends binary data to the message.

Parameters
messageThe string to write to the event log.
typeOne of the T:System.Diagnostics.EventLogEntryType values.
eventIDThe application-specific identifier for the event.
categoryThe application-specific subcategory associated with the message.
rawDataAn array of bytes that holds the binary data associated with the entry.
Exceptions
T:System.ArgumentExceptionThe P:System.Diagnostics.EventLog.Source property of the T:System.Diagnostics.EventLog has not been set.-or- The method attempted to register a new event source, but the computer name in P:System.Diagnostics.EventLog.MachineName is not valid.- or -The source is already registered for a different event log.- or - eventID is less than zero or greater than F:System.UInt16.MaxValue.- or -The message string is longer than 31,839 bytes (32,766 bytes on Windows operating systems before Windows Vista).- or -The source name results in a registry key path longer than 254 characters.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened.
T:System.ComponentModel.InvalidEnumArgumentExceptiontype is not a valid T:System.Diagnostics.EventLogEntryType.
T:System.ComponentModel.Win32ExceptionThe operating system reported an error when writing the event entry to the event log. A Windows error code is not available.

Definition at line 1372 of file EventLog.cs.

◆ WriteEvent() [1/4]

void System.Diagnostics.EventLog.WriteEvent ( EventInstance  instance,
params object []  values 
)

Writes a localized entry to the event log.

Parameters
instanceAn T:System.Diagnostics.EventInstance instance that represents a localized event log entry.
valuesAn array of strings to merge into the message text of the event log entry.
Exceptions
T:System.ArgumentExceptionThe P:System.Diagnostics.EventLog.Source property of the T:System.Diagnostics.EventLog has not been set.-or- The method attempted to register a new event source, but the computer name in P:System.Diagnostics.EventLog.MachineName is not valid.- or -The source is already registered for a different event log.- or - instance.InstanceId is less than zero or greater than F:System.UInt16.MaxValue.- or - values has more than 256 elements.- or -One of the values elements is longer than 32766 bytes.- or -The source name results in a registry key path longer than 254 characters.
T:System.ArgumentNullExceptioninstance is null.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened.
T:System.ComponentModel.Win32ExceptionThe operating system reported an error when writing the event entry to the event log. A Windows error code is not available.

Definition at line 1388 of file EventLog.cs.

◆ WriteEvent() [2/4]

void System.Diagnostics.EventLog.WriteEvent ( EventInstance  instance,
byte []  data,
params object []  values 
)

Writes an event log entry with the given event data, message replacement strings, and associated binary data.

Parameters
instanceAn T:System.Diagnostics.EventInstance instance that represents a localized event log entry.
dataAn array of bytes that holds the binary data associated with the entry.
valuesAn array of strings to merge into the message text of the event log entry.
Exceptions
T:System.ArgumentExceptionThe P:System.Diagnostics.EventLog.Source property of the T:System.Diagnostics.EventLog has not been set.-or- The method attempted to register a new event source, but the computer name in P:System.Diagnostics.EventLog.MachineName is not valid.- or -The source is already registered for a different event log.- or - instance.InstanceId is less than zero or greater than F:System.UInt16.MaxValue.- or - values has more than 256 elements.- or -One of the values elements is longer than 32766 bytes.- or -The source name results in a registry key path longer than 254 characters.
T:System.ArgumentNullExceptioninstance is null.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened.
T:System.ComponentModel.Win32ExceptionThe operating system reported an error when writing the event entry to the event log. A Windows error code is not available.

Definition at line 1405 of file EventLog.cs.

◆ WriteEvent() [3/4]

static void System.Diagnostics.EventLog.WriteEvent ( string  source,
EventInstance  instance,
params object []  values 
)
static

Writes an event log entry with the given event data and message replacement strings, using the specified registered event source.

Parameters
sourceThe name of the event source registered for the application on the specified computer.
instanceAn T:System.Diagnostics.EventInstance instance that represents a localized event log entry.
valuesAn array of strings to merge into the message text of the event log entry.
Exceptions
T:System.ArgumentExceptionThe source value is an empty string ("").- or -The source value is null.- or - instance.InstanceId is less than zero or greater than F:System.UInt16.MaxValue.- or - values has more than 256 elements.- or -One of the values elements is longer than 32766 bytes.- or -The source name results in a registry key path longer than 254 characters.
T:System.ArgumentNullExceptioninstance is null.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened.
T:System.ComponentModel.Win32ExceptionThe operating system reported an error when writing the event entry to the event log. A Windows error code is not available.

Definition at line 1421 of file EventLog.cs.

◆ WriteEvent() [4/4]

static void System.Diagnostics.EventLog.WriteEvent ( string  source,
EventInstance  instance,
byte []  data,
params object []  values 
)
static

Writes an event log entry with the given event data, message replacement strings, and associated binary data, and using the specified registered event source.

Parameters
sourceThe name of the event source registered for the application on the specified computer.
instanceAn T:System.Diagnostics.EventInstance instance that represents a localized event log entry.
dataAn array of bytes that holds the binary data associated with the entry.
valuesAn array of strings to merge into the message text of the event log entry.
Exceptions
T:System.ArgumentExceptionThe source value is an empty string ("").- or -The source value is null.- or - instance.InstanceId is less than zero or greater than F:System.UInt16.MaxValue.- or - values has more than 256 elements.- or -One of the values elements is longer than 32766 bytes.- or -The source name results in a registry key path longer than 254 characters.
T:System.ArgumentNullExceptioninstance is null.
T:System.InvalidOperationExceptionThe registry key for the event log could not be opened.
T:System.ComponentModel.Win32ExceptionThe operating system reported an error when writing the event entry to the event log. A Windows error code is not available.

Definition at line 1441 of file EventLog.cs.

Property Documentation

◆ EnableRaisingEvents

bool System.Diagnostics.EventLog.EnableRaisingEvents
getset

Gets or sets a value indicating whether the T:System.Diagnostics.EventLog receives E:System.Diagnostics.EventLog.EntryWritten event notifications.

Returns
true if the T:System.Diagnostics.EventLog receives notification when an entry is written to the log; otherwise, false.
Exceptions
T:System.InvalidOperationExceptionThe event log is on a remote computer.

Definition at line 188 of file EventLog.cs.

◆ Entries

EventLogEntryCollection System.Diagnostics.EventLog.Entries
get

Gets the contents of the event log.

Returns
An T:System.Diagnostics.EventLogEntryCollection holding the entries in the event log. Each entry is associated with an instance of the T:System.Diagnostics.EventLogEntry class.

Definition at line 60 of file EventLog.cs.

◆ EntryWritten

EntryWrittenEventHandler System.Diagnostics.EventLog.EntryWritten
addremove

Occurs when an entry is written to an event log on the local computer.

Definition at line 249 of file EventLog.cs.

◆ Log

string System.Diagnostics.EventLog.Log
getset

Gets or sets the name of the log to read from or write to.

Returns
The name of the log. This can be Application, System, Security, or a custom log name. The default is an empty string ("").

Definition at line 87 of file EventLog.cs.

◆ LogDisplayName

string System.Diagnostics.EventLog.LogDisplayName
get

Gets the event log's friendly name.

Returns
A name that represents the event log in the system's event viewer.
Exceptions
T:System.InvalidOperationExceptionThe specified P:System.Diagnostics.EventLog.Log does not exist in the registry for this computer.

Definition at line 72 of file EventLog.cs.

◆ MachineName

string System.Diagnostics.EventLog.MachineName
getset

Gets or sets the name of the computer on which to read or write events.

Returns
The name of the server on which the event log resides. The default is the local computer (".").
Exceptions
T:System.ArgumentExceptionThe computer name is invalid.

Definition at line 115 of file EventLog.cs.

◆ MaximumKilobytes

long System.Diagnostics.EventLog.MaximumKilobytes
getset

Gets or sets the maximum event log size in kilobytes.

Returns
The maximum event log size in kilobytes. The default is 512, indicating a maximum file size of 512 kilobytes.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe specified value is less than 64, or greater than 4194240, or not an even multiple of 64.
T:System.InvalidOperationExceptionThe P:System.Diagnostics.EventLog.Log value is not a valid log name.- or -The registry key for the event log could not be opened on the target computer.

Definition at line 143 of file EventLog.cs.

◆ MinimumRetentionDays

int System.Diagnostics.EventLog.MinimumRetentionDays
get

Gets the number of days to retain entries in the event log.

Returns
The number of days that entries in the event log are retained. The default value is 7.

Definition at line 171 of file EventLog.cs.

◆ OverflowAction

OverflowAction System.Diagnostics.EventLog.OverflowAction
get

Gets the configured behavior for storing new entries when the event log reaches its maximum log file size.

Returns
The T:System.Diagnostics.OverflowAction value that specifies the configured behavior for storing new entries when the event log reaches its maximum log size. The default is F:System.Diagnostics.OverflowAction.OverwriteOlder.

Definition at line 159 of file EventLog.cs.

◆ Source

string System.Diagnostics.EventLog.Source
getset

Gets or sets the source name to register and use when writing to the event log.

Returns
The name registered with the event log as a source of entries. The default is an empty string ("").
Exceptions
T:System.ArgumentExceptionThe source name results in a registry key path longer than 254 characters.

Definition at line 226 of file EventLog.cs.

◆ SynchronizingObject

ISynchronizeInvoke System.Diagnostics.EventLog.SynchronizingObject
getset

Gets or sets the object used to marshal the event handler calls issued as a result of an T:System.Diagnostics.EventLog entry written event.

Returns
The T:System.ComponentModel.ISynchronizeInvoke used to marshal event-handler calls issued as a result of an E:System.Diagnostics.EventLog.EntryWritten event on the event log.

Definition at line 205 of file EventLog.cs.


The documentation for this class was generated from the following file: