Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing events to Windows Event Log using Coldfusion

Is there a way (built-in or underlying java library installed with ColdFusion) that would enable a ColdFusion 10 application to write messages to the Windows Event Log?

like image 616
rodmunera Avatar asked Dec 22 '14 19:12

rodmunera


People also ask

How do I create a Windows event log?

Open "Event Viewer" by clicking the "Start" button. Click "Control Panel" > "System and Security" > "Administrative Tools", and then double-click "Event Viewer" Click to expand "Windows Logs" in the left pane, and then select "Application". Click the "Action" menu and select "Save All Events As".

What are the three main types of event logs that come with Windows?

Types of Event Logs Each event entry is classified by Type to identify the severity of the event. They are Information, Warning, Error, Success Audit (Security Log) and Failure Audit (Security Log).

How does Windows event logging work?

Event logging provides a standard, centralized way for applications (and the operating system) to record important software and hardware events. The event logging service records events from various sources and stores them in a single collection called an event log.


1 Answers

You can use Log4J to accomplish this. There is also a DLL that's required to be placed on the PATH of the Windows file system (depending on your environment). See the NTEventLogAppender class for details:

Log4J will be packaged with your build since Hibernate uses it. However, you will likely need to do some extra configuring per the DLL I mentioned above (also noted in the referenced javadocs).

You can also check out Log4jna, which has native appenders unlike Log4J. Using this library will not require you to mess with the DLL dependency for Log4J. This does not come with CF10 though. It's out of scope of your question, but still may be an option to consider.

An example of code you can potentially use if you stick with Log4J (reference to the PatternLayout):

oLogger = createObject("java", "org.apache.log4j.Logger");
oNTAppender = createObject("java", "org.apache.log4j.nt.NTEventLogAppender");
oLayout = createObject("java", "PatternLayout").init("[%c][%l][%p][%thread]: %m%n");

// create the appender with your source and layout
oNTAppender = oNTAppender.init("[your source text]", oLayout);

// add this appender to the logger
oLogger.addAppender(oNTAppender);
like image 175
Tristan Lee Avatar answered Nov 15 '22 13:11

Tristan Lee