Event Log

Use Event Log interface to add log on Windows


Introduction

This is a wrap of Win32 API: ReportEvent. So currently, the Event Log supports Windows Only.


API Class

There is one API class EventLog. There are a series of method to add event log:

public class EventLog
{
    /**
     * Writes an entry at the end of the event log,
     * providing associated strings and binary data
     * 
     * @param type The type of event being logged
     * @param cat  The event category
     * @param id   The event identifier, which specifies the message that goes with
     *             this event as an entry in the message file 
     *             associated with the event source
     * @param msgs An array of strings that are merged into the message before the 
     *             message is displayed to the user
     * @param data The binary data associated with the report
     */
    public void reportEvent (short type, short cat, int id);
    public void reportEvent (short type, short cat, int id, String msg);
    public void reportEvent (short type, short cat, int id, String[] msgs);
    public void reportEvent (short type, short cat, int id, String msg, byte[] data);
    public void reportEvent (short type, short cat, int id, String[] msgs, byte[] data);
}

Demo Code

The usage of EventLog is: to new an instance of EventLog and call reportEvent() method.

// new an instance of EventLog
EventLog event = new EventLog();

// to add a log
event.reportEvent(EventLog.INFORMATION, (short)1, 1, "This is DemoEventLog1");

See Also

Comments

Library Not Found

i run the code then i got this error.:-

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.regexlab.j2e.EventLog.init(Ljava/lang/String;Ljava/lang/String;)V
        at com.regexlab.j2e.EventLog.init(Native Method)
        at com.regexlab.j2e.EventLog.<init>(EventLog.java:47)
        at DemoEventLog.main(DemoEventLog.java:9)

can you please help e on this.

Add new comment