Reputation: 552
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?
Upvotes: 5
Views: 370
Reputation: 1220
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);
Upvotes: 7