Class EventLogAppender
Writes events to the system event log.
public class EventLogAppender : AppenderSkeleton, IBulkAppender, IAppender, IOptionHandler, IFlushable
- Inheritance
-
EventLogAppender
- Implements
- Inherited Members
Remarks
The appender will fail if you try to write using an event source that doesn't exist unless it is running with local administrator privileges. See also http://logging.apache.org/log4net/release/faq.html#trouble-EventLog
The EventID of the event log entry can be
set using the EventID property (Properties)
on the LoggingEvent.
The Category of the event log entry can be set using the Category property (Properties) on the LoggingEvent.
There is a limit of 32K characters for an event log message
When configuring the EventLogAppender a mapping can be specified to map a logging level to an event log entry type. For example:
<mapping>
<level value="ERROR" />
<eventLogEntryType value="Error" />
</mapping>
<mapping>
<level value="DEBUG" />
<eventLogEntryType value="Information" />
</mapping>
The Level is the standard log4net logging level and eventLogEntryType can be any value from the EventLogEntryType enum, i.e.:
- Erroran error event
- Warninga warning event
- Informationan informational event
Constructors
EventLogAppender()
Initializes a new instance of the EventLogAppender class.
public EventLogAppender()
Remarks
Default constructor.
Properties
ApplicationName
Property used to set the Application name. This appears in the event logs when logging.
public string ApplicationName { get; set; }
Property Value
- string
The string used to distinguish events from different sources.
Remarks
Sets the event log source property.
Category
Gets or sets the Category to use unless one is explicitly specified via the LoggingEvent's properties.
public short Category { get; set; }
Property Value
Remarks
The Category of the event log entry will normally be set using the Category property (Properties) on the LoggingEvent. This property provides the fallback value which defaults to 0.
EventId
Gets or sets the EventId to use unless one is explicitly specified via the LoggingEvent's properties.
public int EventId { get; set; }
Property Value
Remarks
The EventID of the event log entry will normally be
set using the EventID property (Properties)
on the LoggingEvent.
This property provides the fallback value which defaults to 0.
LogName
The name of the log where messages will be stored.
public string LogName { get; set; }
Property Value
- string
The string name of the log where messages will be stored.
Remarks
This is the name of the log as it appears in the Event Viewer
tree. The default value is to log into the Application
log, this is where most applications write their events. However
if you need a separate log for your application (or applications)
then you should set the LogName appropriately.
This should not be used to distinguish your event log messages from those of other applications, the ApplicationName property should be used to distinguish events. This property should be used to group together events into a single log.
MachineName
This property is used to return the name of the computer to use when accessing the event logs. Currently, this is the current computer, denoted by a dot "."
public string MachineName { get; }
Property Value
- string
The string name of the machine holding the event log that will be logged into.
Remarks
This property cannot be changed. It is currently set to '.' i.e. the local machine. This may be changed in future.
RequiresLayout
This appender requires a log4net.Layout to be set.
protected override bool RequiresLayout { get; }
Property Value
SecurityContext
Gets or sets the SecurityContext used to write to the EventLog.
public SecurityContext? SecurityContext { get; set; }
Property Value
- SecurityContext
The SecurityContext used to write to the EventLog.
Remarks
The system security context used to write to the EventLog.
Unless a SecurityContext specified here for this appender the DefaultProvider is queried for the security context to use. The default behavior is to use the security context of the current thread.
Methods
ActivateOptions()
Initialize the appender based on the options set
public override void ActivateOptions()
Remarks
This is part of the IOptionHandler delayed object activation scheme. The ActivateOptions() method must be called on this object after the configuration properties have been set. Until ActivateOptions() is called this object is in an undefined state and must not be used.
If any of the configuration properties are modified then ActivateOptions() must be called again.
AddMapping(Level2EventLogEntryType)
Add a mapping of level to EventLogEntryType - done by the config file
public void AddMapping(EventLogAppender.Level2EventLogEntryType mapping)
Parameters
mappingEventLogAppender.Level2EventLogEntryTypeThe mapping to add
Remarks
Add a EventLogAppender.Level2EventLogEntryType mapping to this appender. Each mapping defines the event log entry type for a level.
Append(LoggingEvent)
This method is called by the DoAppend(LoggingEvent) method.
protected override void Append(LoggingEvent loggingEvent)
Parameters
loggingEventLoggingEventthe event to log
Remarks
Writes the event to the system event log using the ApplicationName.
If the event has an EventID property (see Properties)
set then this integer will be used as the event log event id.
There is a limit of 32K characters for an event log message
GetEntryType(Level?)
Get the equivalent EventLogEntryType for a Level level
public virtual EventLogEntryType GetEntryType(Level? level)
Parameters
levelLevelthe Level to convert to an EventLogEntryType
Returns
- EventLogEntryType
The equivalent EventLogEntryType for a Level
level
Remarks
Because there are fewer applicable EventLogEntryType values to use in logging levels than there are in the Level this is a one way mapping. There is a loss of information during the conversion.