Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
4.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: eventlog.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _INC_CSCUI_EVENTLOG_H
  11. #define _INC_CSCUI_EVENTLOG_H
  12. #ifndef _WINDOWS_
  13. # include <windows.h>
  14. #endif
  15. //
  16. // This class provides basic NT event logging capability. It provides only
  17. // a subset of the full capability provided by the NT event logging APIs.
  18. // I wanted a simple way to write messages to the event log. No reading
  19. // of event log entries is supported.
  20. //
  21. class CEventLog
  22. {
  23. public:
  24. //
  25. // Number conversion formats.
  26. //
  27. enum eFmt {
  28. eFmtDec, // Display as decimal.
  29. eFmtHex, // Display as hex
  30. eFmtSysErr // Display as win32 error text string.
  31. };
  32. class CStrArray
  33. {
  34. public:
  35. CStrArray(void);
  36. ~CStrArray(void)
  37. { Destroy(); }
  38. bool Append(LPCTSTR psz);
  39. void Clear(void)
  40. { Destroy(); }
  41. int Count(void) const
  42. { return m_cEntries; }
  43. LPCTSTR Get(int iEntry) const;
  44. operator LPCTSTR* () const
  45. { return (LPCTSTR *)m_rgpsz; }
  46. private:
  47. enum { MAX_ENTRIES = 8 };
  48. int m_cEntries;
  49. LPTSTR m_rgpsz[MAX_ENTRIES];
  50. void Destroy(void);
  51. //
  52. // Prevent copy.
  53. //
  54. CStrArray(const CStrArray& rhs);
  55. CStrArray& operator = (const CStrArray& rhs);
  56. };
  57. CEventLog(void)
  58. : m_hLog(NULL)
  59. { }
  60. ~CEventLog(void);
  61. HRESULT Initialize(LPCTSTR pszEventSource);
  62. bool IsInitialized(void)
  63. { return NULL != m_hLog; }
  64. void Close(void);
  65. HRESULT ReportEvent(WORD wType,
  66. WORD wCategory,
  67. DWORD dwEventID,
  68. PSID lpUserSid = NULL,
  69. LPVOID pvRawData = NULL,
  70. DWORD cbRawData = 0);
  71. //
  72. // Push replacement data onto a stack to replace the
  73. // %1, %2 etc. parameters in the message strings.
  74. //
  75. void Push(HRESULT hr, eFmt = eFmtDec);
  76. void Push(LPCTSTR psz);
  77. private:
  78. HANDLE m_hLog;
  79. CStrArray m_rgstrText;
  80. //
  81. // Prevent copy.
  82. //
  83. CEventLog(const CEventLog& rhs);
  84. CEventLog& operator = (const CEventLog& rhs);
  85. };
  86. //
  87. // Wrap the CEventLog class so we can control log initialization
  88. // and also filter events based on the CSCUI event logging level.
  89. // The idea here is to create a CscuiEventLog object whenever you
  90. // want to write to the event log. The ReportEvent member has
  91. // been designed to handle log initialization as well as filtering
  92. // message output to respect the current CSCUI event logging level
  93. // set in the registry/policy. It's recommended that the
  94. // CscuiEventLog object be created as a local variable so that
  95. // once the reporting is complete, the object is destroyed and
  96. // the system event log handle is closed.
  97. //
  98. class CscuiEventLog
  99. {
  100. public:
  101. CscuiEventLog(void)
  102. : m_iEventLoggingLevel(CConfig::GetSingleton().EventLoggingLevel()) { }
  103. ~CscuiEventLog(void) { }
  104. HRESULT ReportEvent(WORD wType,
  105. DWORD dwEventID,
  106. int iMinLevel,
  107. PSID lpUserSid = NULL,
  108. LPVOID pvRawData = NULL,
  109. DWORD cbRawData = 0);
  110. bool LoggingEnabled(void) const
  111. { return 0 < m_iEventLoggingLevel; }
  112. void Push(HRESULT hr, CEventLog::eFmt fmt)
  113. { m_log.Push(hr, fmt); }
  114. void Push(LPCTSTR psz)
  115. { m_log.Push(psz); }
  116. private:
  117. CEventLog m_log;
  118. int m_iEventLoggingLevel;
  119. };
  120. #endif // _INC_CSCUI_EVENTLOG_H