NTEventLogAppender.hh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * NTEventLogAppender.hh
  3. *
  4. * See the COPYING file for the terms of usage and distribution.
  5. */
  6. #ifndef _LOG4CPP_NTEVENTLOGAPPENDER_HH
  7. #define _LOG4CPP_NTEVENTLOGAPPENDER_HH
  8. #ifdef _WIN32 // only available on Win32
  9. // deal with ERROR #define
  10. // N.B. This #includes windows.h with NOGDI and WIN32_LEAN_AND_MEAN #defined.
  11. // If this is not what the user wants, #include windows.h before this file.
  12. #ifndef _WINDOWS_
  13. # ifndef NOGDI
  14. # define NOGDI // this will circumvent the ERROR #define in windows.h
  15. # define LOG4CPP_UNDEFINE_NOGDI
  16. # endif
  17. # ifndef WIN32_LEAN_AND_MEAN
  18. # define WIN32_LEAN_AND_MEAN
  19. # define LOG4CPP_UNDEFINE_WIN32_LEAN_AND_MEAN
  20. # endif
  21. # include <windows.h>
  22. # ifdef LOG4CPP_UNDEFINE_NOGDI
  23. # undef NOGDI
  24. # endif
  25. # ifdef LOG4CPP_UNDEFINE_WIN32_LEAN_AND_MEAN
  26. # undef WIN32_LEAN_AND_MEAN
  27. # endif
  28. #endif // done dealing with ERROR #define
  29. #include <log4cpp/Portability.hh>
  30. #include <log4cpp/AppenderSkeleton.hh>
  31. LOG4CPP_NS_BEGIN
  32. /**
  33. * NTEventLogAppender is an Appender that sends LoggingEvents to the
  34. * Windows event log.
  35. * Building log4cpp.dsp/log4cppDLL.dsp creates the resource DLL NTEventLogAppender.dll.
  36. * Do not forget to place this DLL in a directory that is on the PATH
  37. * of the Windows system. Otherwise, the category and message will not display
  38. * correctly in Event Viewer.<BR>
  39. * <B>NB:</B> This class is only available on Win32 platforms.
  40. **/
  41. class LOG4CPP_EXPORT NTEventLogAppender : public AppenderSkeleton {
  42. public:
  43. /**
  44. * Instantiate an NTEventLogAppender with given name and source.
  45. * @param name The name of the Appender
  46. * @param sourceName The source name to log
  47. **/
  48. NTEventLogAppender(const std::string& name, const std::string& sourceName);
  49. virtual ~NTEventLogAppender();
  50. /**
  51. * Calls open() and close()
  52. **/
  53. virtual bool reopen();
  54. virtual void close();
  55. /**
  56. * The NTEventLogAppender does its own Layout.
  57. * @returns false
  58. **/
  59. virtual bool requiresLayout() const;
  60. virtual void setLayout(Layout* layout);
  61. protected:
  62. WORD getCategory(Priority::Value priority);
  63. WORD getType(Priority::Value priority);
  64. HKEY regGetKey(TCHAR *subkey, DWORD *disposition);
  65. void regSetString(HKEY hkey, TCHAR *name, TCHAR *value);
  66. void regSetDword(HKEY hkey, TCHAR *name, DWORD value);
  67. void addRegistryInfo(const char *source);
  68. virtual void open();
  69. /**
  70. * Sends a LoggingEvent to NT Event log.
  71. * @param event the LoggingEvent to log.
  72. **/
  73. virtual void _append(const LoggingEvent& event);
  74. HANDLE _hEventSource;
  75. std::string _strSourceName;
  76. };
  77. LOG4CPP_NS_END
  78. #else // WIN32
  79. #error NTEventLoggAppender is not available on on Win32 platforms
  80. #endif // WIN32
  81. #endif // _LOG4CPP_NTEVENTLOGAPPENDER_HH