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?
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".
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).
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With