org.dblock.log4jna.nt

## Class Win32EventLogAppender

- java.lang.Object
- - org.apache.logging.log4j.core.AbstractLifeCycle
  - - org.apache.logging.log4j.core.filter.AbstractFilterable
    - - org.apache.logging.log4j.core.appender.AbstractAppender
      - - org.dblock.log4jna.nt.Win32EventLogAppender

- All Implemented Interfaces:
    Appender, Filterable, LifeCycle

      @Plugin(name="Win32EventLog",
              category="Core",
              elementType="appender",
              printObject=true)
      public class Win32EventLogAppender
      extends AbstractAppender

  Append to the NT event log system.

  WARNING This appender can only be installed and used on a Windows system.

  Do not forget to place jna.jar and platform.jar in the CLASSPATH.

  Author:
    Chris Taylor, Jim Cakalic, Daniel Doubrovkine, Tony Niemira, Claudio Trajtenberg

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle

      `LifeCycle.State`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private String` | `_application`
    `private String` | `_categoryMessageFile`
    `private String` | `_eventMessageFile`
    `private WinNT.HANDLE` | `_handle`
    `private String` | `_server`
    `private String` | `_source`
    `private static int` | `CATEGORY_COUNT`
    `private static String` | `CATEGORY_MESSAGE_FILE`
    `private static String` | `DEFAULT_APPLICATION`
    `private static String` | `DEFAULT_SOURCE`
    `private static String` | `EVENT_LOG_PATH`
    `private static String` | `EVENT_MESSAGE_FILE`
    `private static int` | `TYPES_SUPPORTED`

    - ### Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle

      `LOGGER`

    - ### Fields inherited from interface org.apache.logging.log4j.core.Appender

      `ELEMENT_TYPE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Win32EventLogAppender(String name, String server, String source, String application, String eventMessageFile, String categoryMessageFile, Layout<? extends Serializable> layout, Filter filter)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `activateOptions()`
    `void` | `append(LogEvent event)`
    `void` | `close()`
    `private void` | `createAndSetAllKeys(String eventMessageFile, String categoryMessageFile, String eventSourceKeyPath)`
    `static Win32EventLogAppender` | `createAppender(String name, String server, String source, String application, String eventMessageFile, String categoryMessageFile, Layout<? extends Serializable> layout, Filter filter)`
    `void` | `finalize()`
    `String` | `getApplication()`
    `String` | `getCategoryMessageFile()`
    `private static int` | `getEventLogCategory(Level level)` Convert log4j Priority to an EventLog category.
    `private static int` | `getEventLogType(Level level)` Convert log4j Priority to an EventLog type.
    `String` | `getEventMessageFile()`
    `String` | `getSource()`
    `private void` | `registerEventSource()`
    `private WinNT.HANDLE` | `registerEventSource(String server, String source, String application, String eventMessageFile, String categoryMessageFile)`
    `boolean` | `requiresLayout()` The `Win32EventLogAppender` requires a layout.
    `void` | `setApplication(String application)` The Application option which names the subsection of the 'Applications and Services Log'.
    `void` | `setCategoryMessageFile(String categoryMessageFile)` The CategoryMessageFile option which sets file location of the Catagory Messages
    `void` | `setEventMessageFile(String eventMessageFile)` The EventMessageFile option which sets file location of the Event Messages
    `void` | `setSource(String source)` The Source option which names the source of the event.
    `private void` | `setVariableKeys(String eventMessageFile, String categoryMessageFile, String eventSourceKeyPath)` Set the file location only if it does not exist or has changed.

    - ### Methods inherited from class org.apache.logging.log4j.core.appender.AbstractAppender

      `error, error, error, getHandler, getLayout, getName, ignoreExceptions, parseInt, setHandler, toString`

    - ### Methods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable

      `addFilter, getFilter, hasFilter, isFiltered, removeFilter, start, stop`

    - ### Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle

      `equalsImpl, getState, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.apache.logging.log4j.core.LifeCycle

      `getState, initialize, isStarted, isStopped, start, stop`

- - ### Field Detail

    - #### EVENT_LOG_PATH

          private static final String EVENT_LOG_PATH

      See Also:
        Constant Field Values

    - #### CATEGORY_MESSAGE_FILE

          private static final String CATEGORY_MESSAGE_FILE

      See Also:
        Constant Field Values

    - #### EVENT_MESSAGE_FILE

          private static final String EVENT_MESSAGE_FILE

      See Also:
        Constant Field Values

    - #### CATEGORY_COUNT

          private static final int CATEGORY_COUNT

      See Also:
        Constant Field Values

    - #### TYPES_SUPPORTED

          private static final int TYPES_SUPPORTED

      See Also:
        Constant Field Values

    - #### DEFAULT_SOURCE

          private static final String DEFAULT_SOURCE

      See Also:
        Constant Field Values

    - #### DEFAULT_APPLICATION

          private static final String DEFAULT_APPLICATION

      See Also:
        Constant Field Values

    - #### _source

          private String _source

    - #### _server

          private String _server

    - #### _application

          private String _application

    - #### _eventMessageFile

          private String _eventMessageFile

    - #### _categoryMessageFile

          private String _categoryMessageFile

    - #### _handle

          private WinNT.HANDLE _handle

  - ### Constructor Detail

    - #### Win32EventLogAppender

          public Win32EventLogAppender(String name,
                                       String server,
                                       String source,
                                       String application,
                                       String eventMessageFile,
                                       String categoryMessageFile,
                                       Layout<? extends Serializable> layout,
                                       Filter filter)

      Parameters:
        `name` - The appender name Win32EventLog
        `server` - The server for remote logging
        `source` - The Event View Source
        `application` - The Event View application (location)
        `eventMessageFile` - The message file location in the file system
        `categoryMessageFile` - The message file location in the file system
        `layout` - A Log4j Layout
        `filter` - A Log4j Filter

  - ### Method Detail

    - #### createAppender

          @PluginFactory
          public static Win32EventLogAppender createAppender(@PluginAttribute(value="name")
                                                                             String name,
                                                                             @PluginAttribute(value="server")
                                                                             String server,
                                                                             @PluginAttribute(value="source")
                                                                             String source,
                                                                             @PluginAttribute(value="application")
                                                                             String application,
                                                                             @PluginAttribute(value="eventMessageFile")
                                                                             String eventMessageFile,
                                                                             @PluginAttribute(value="categoryMessageFile")
                                                                             String categoryMessageFile,
                                                                             @PluginElement(value="Layout")
                                                                             Layout<? extends Serializable> layout,
                                                                             @PluginElement(value="Filters")
                                                                             Filter filter)

      Parameters:
        `name` - The appender name Win32EventLog
        `server` - The server for remote logging
        `source` - The Event View Source
        `application` - The Event View application (location)
        `eventMessageFile` - The message file location in the file system
        `categoryMessageFile` - The message file location in the file system
        `layout` - A Log4j Layout
        `filter` - A Log4j Filter
      Returns:

    - #### setSource

          public void setSource(String source)

      The Source option which names the source of the event. The current value of this constant is Source.

    - #### getSource

          public String getSource()

      Returns:

    - #### setApplication

          public void setApplication(String application)

      The Application option which names the subsection of the 'Applications and Services Log'. The default value of this constant is Application.
      Parameters:
        `application` - The Event View application (location)

    - #### getApplication

          public String getApplication()

      Returns:

    - #### close

          public void close()

    - #### setEventMessageFile

          public void setEventMessageFile(String eventMessageFile)

      The EventMessageFile option which sets file location of the Event Messages
      Parameters:
        `eventMessageFile` - The message file location in the file system

    - #### getEventMessageFile

          public String getEventMessageFile()

      Returns:

    - #### setCategoryMessageFile

          public void setCategoryMessageFile(String categoryMessageFile)

      The CategoryMessageFile option which sets file location of the Catagory Messages
      Parameters:
        `categoryMessageFile` - The message file location in the file system

    - #### getCategoryMessageFile

          public String getCategoryMessageFile()

      Returns:

    - #### registerEventSource

          private void registerEventSource()

    - #### activateOptions

          public void activateOptions()

    - #### append

          public void append(LogEvent event)

    - #### finalize

          public void finalize()

      Overrides:
        `finalize` in class `Object`

    - #### requiresLayout

          public boolean requiresLayout()

      The `Win32EventLogAppender` requires a layout. Hence, this method always returns `true`.

    - #### registerEventSource

          private WinNT.HANDLE registerEventSource(String server,
                                                   String source,
                                                   String application,
                                                   String eventMessageFile,
                                                   String categoryMessageFile)

      Parameters:
        `server` - The server for remote logging
        `source` - The Event View Source
        `application` - The Event View application (location)
        `eventMessageFile` - The message file location in the file system
        `categoryMessageFile` - The message file location in the file system
      Returns:

    - #### createAndSetAllKeys

          private void createAndSetAllKeys(String eventMessageFile,
                                           String categoryMessageFile,
                                           String eventSourceKeyPath)

      Parameters:
        `eventMessageFile` - The message file location in the file system
        `categoryMessageFile` - The message file location in the file system
        `eventSourceKeyPath` - The registry path

    - #### setVariableKeys

          private void setVariableKeys(String eventMessageFile,
                                       String categoryMessageFile,
                                       String eventSourceKeyPath)

      Set the file location only if it does not exist or has changed.
      Parameters:
        `eventMessageFile` - The message file location in the file system
        `categoryMessageFile` - The message file location in the file system
        `eventSourceKeyPath` - The registry path

    - #### getEventLogType

          private static int getEventLogType(Level level)

      Convert log4j Priority to an EventLog type. The log4j package supports 8 defined priorities, but the NT EventLog only knows 3 event types of interest to us: ERROR, WARNING, and INFO.
      Parameters:
        `level` - Log4j priority.
      Returns:
        EventLog type.

    - #### getEventLogCategory

          private static int getEventLogCategory(Level level)

      Convert log4j Priority to an EventLog category. Each category is backed by a message resource so that proper category names will be displayed in the NT Event Viewer.
      Parameters:
        `level` - Log4J priority.
      Returns:
        EventLog category.

Copyright © 2016 The Log4JNA Team. All rights reserved.