Windows Event Log Writer

Class names

Writer: NSoft.Log.Writers.EventLog.EventLogWriter.
Configuration: NSoft.Log.Writers.EventLog.EventLogWriterSettings.

Description

This writer stores data to windows event log
Each channel will be mapped on event source. You can define custom mappings in writer settings.
By default data will be stored in Message field, but it can be customized.
Each channel uses it's own event source. Writer creates event log and event sources if they are not exists.

Available settings:
  • DataDelimeter - char or string that used as delimeter for stored data. Default value - Tab (\t).
  • EntryType - type of event log entry, that will be created for data. Default value: Information. You should use values from EventLogEntryType enum.
  • LogName - the name of event log.
  • MachineName - network adress or name of the computer where event log is situated. Default value - "." (dot).
  • Mappings - special mappings configuration. Mapping value - special event source name, that will be used for channel. By default writer used same event source as channel name.
  • DataMappings - custom data mapping settings. Each element looks like:
    • ChannelName - the name of channel. Writer will be used this settings for that channel.
    • Category - the identifier of event log category. Value should be Int16. You can use parameters {0}..{N}, where N equals data items count minus one.
    • Event - the identifier of event log category. Value should be Int32. You can use parameters {0}..{N}, where N equals data items count minus one.
    • EntryType - type of event log entry, that will be created for data. Default value: Information. You should use values from EventLogEntryType enum.
    • Message - format of the event log message. You can use parameters {0}..{N}, where N equals data items count minus one.

Configuration samples.

For example we define two channels:
  • Information - channel for some information messages.
  • Exception - channel for errors information.

We want use for channel "Information" event source "Info".
Also we want customize data mappings for channel "Exception".

There is configuration:

<add id="1" type="NSoft.Log.Writers.EventLog.EventLogWriter, NSoft.Log.Writers" configurationType="NSoft.Log.Writers.EventLog.EventLogWriterSettings, NSoft.Log.Writers">
  <configuration>
    <dataDelimeter>&#9;</dataDelimeter>
    <entryType>Information</entryType>
    <machineName>.</machineName>
    <logName>MyLog</logName>
    <dataMappings>
      <add channelName="Exception" category="2" event="1212" entryType="Error" message="DateTime: {0}&#13;&#10;Message:&#13;&#10;{1}&#13;&#10;Stack:&#13;&#10;{2}" />
    </dataMappings>

    <mappings>
      <add channelName="Information" value="Info"/>
    </mappings>
  </configuration>
</add>

Last edited Apr 2, 2011 at 7:41 AM by Tesh, version 3