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
- See Event Log Introduction page for more information about Event Log.
- See Event Log Demo page for demo program.
- Integrate API - 20K, API library to integrate with generated exe.
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.
Make sure you have enabled at Step 4
1) This feature is supported on Windows only.
2) Then, please make sure you have enabled it at Step 4.
Add new comment