The first time you run the test suite or any application using Log4JNA, Log4JNA attempts to write the necessary entries in WindowsTM Registry. If you don't have Administrator privileges the run fails.
In order for the tests to pass you must run them as Administrator or set up the registry before your first run.
Open a command window as administrator and execute mvn test
.
If you are using an IDE launch it as Administrator import the Maven projects and run the tests.
Please be careful and do not check IDE configuration files into GitHub, you can add the project to your IDE following the instructions bellow.
Eclipse configuration files are already added to .gitignore
, please add any configuration file created by your IDE to the ignore file.
See this article to import the Maven projects.
See this article to import the Maven projects.
See this article to import the Maven projects.
The Win32EventlogAppender.dll
file is provided in the source as a test asset in
<project-location>/log4jna-api/src/test/resources
.
The tests configure Log4J programmatically and write into Event Viewer-->Windows Logs-->Application
.
- Open
regedit
and browse toHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application\
- Right click and select
New Key
, name itLog4jnaTest
- Add the following entries to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application\Log4jnaTest
Entry name | Entry Type | Value |
---|---|---|
TypesSupported | DWORD (32 bit) Value (REG_DWORD) | 0x7 |
CategoryCount | DWORD (32 bit) Value (REG_DWORD) | 0x6 |
EventMessageFile | String Value (REG_SZ) | <Full path to>\Win32EventlogAppender.dll |
CategoryMessageFile | String Value (REG_SZ) | <Full path to>\Win32EventlogAppender.dll |
The registry should look like this:
The Win32EventlogAppender.dll
and Log4J 2 configuration files are provided in the source as an application asset in
<project-location>/log4jna-demo/src/main/resources
.
The default Log4J configuration is log4j2.xml
and writes into Event Viewer-->Application and Service Logs-->Win32LogApplication
.
- Open
regedit
and browse toHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\
- Right click and select
New Key
, name itWin32LogApplication
- Add another key to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Win32LogApplication
, name itWinLogger
- Add another key to
- Add the following entries to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Win32LogApplication\WinLogger
Entry name | Entry Type | Value |
---|---|---|
TypesSupported | DWORD (32 bit) Value (REG_DWORD) | 0x7 |
CategoryCount | DWORD (32 bit) Value (REG_DWORD) | 0x6 |
EventMessageFile | String Value (REG_SZ) | <Full path to>\Win32EventlogAppender.dll |
CategoryMessageFile | String Value (REG_SZ) | <Full path to>\Win32EventlogAppender.dll |
The registry should look like this: