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.

113 lines
2.5 KiB

  1. ////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2000, Microsoft Corporation.
  4. //
  5. // All rights reserved.
  6. //
  7. // Module Name:
  8. //
  9. // wmi_EventLog.cpp
  10. //
  11. // Abstract:
  12. //
  13. // defines event log specific ( see wmi_eventlog_base )
  14. //
  15. // History:
  16. //
  17. // initial a-marius
  18. //
  19. ////////////////////////////////////////////////////////////////////////////////////
  20. #include "PreComp.h"
  21. // definitions
  22. #include "wmi_EventLog.h"
  23. // debuging features
  24. #ifndef _INC_CRTDBG
  25. #include <crtdbg.h>
  26. #endif _INC_CRTDBG
  27. // new stores file/line info
  28. #ifdef _DEBUG
  29. #ifndef NEW
  30. #define NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )
  31. #define new NEW
  32. #endif NEW
  33. #endif _DEBUG
  34. // need macros
  35. #ifndef __ASSERT_VERIFY__
  36. #include "__macro_assert.h"
  37. #endif __ASSERT_VERIFY__
  38. /////////////////////////////////////////////////////////////////////////////////////////
  39. // construction & destruction
  40. /////////////////////////////////////////////////////////////////////////////////////////
  41. CPerformanceEventLog::CPerformanceEventLog( LPTSTR szApp ) :
  42. CPerformanceEventLogBase ( szApp ),
  43. m_dwMessageLevel(0)
  44. {
  45. if ( ! m_dwMessageLevel )
  46. {
  47. InitializeMessageLevel();
  48. }
  49. }
  50. CPerformanceEventLog::CPerformanceEventLog(DWORD dwMessageLevel, LPTSTR szApp ) :
  51. CPerformanceEventLogBase ( szApp ),
  52. m_dwMessageLevel(dwMessageLevel)
  53. {
  54. if ( ! m_dwMessageLevel )
  55. {
  56. InitializeMessageLevel();
  57. }
  58. }
  59. CPerformanceEventLog::~CPerformanceEventLog()
  60. {
  61. m_dwMessageLevel= 0;
  62. }
  63. /////////////////////////////////////////////////////////////////////////////////////////
  64. // helpers
  65. /////////////////////////////////////////////////////////////////////////////////////////
  66. void CPerformanceEventLog::InitializeMessageLevel ( void )
  67. {
  68. DWORD dwResult = 0;
  69. DWORD dwLogLevel = 0;
  70. HKEY hKey = NULL;
  71. dwResult = ::RegOpenKeyEx ( HKEY_LOCAL_MACHINE,
  72. _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\PerfLib"),
  73. NULL,
  74. KEY_READ,
  75. &hKey );
  76. if ( ERROR_SUCCESS == dwResult )
  77. {
  78. DWORD dwLogLevelSize = sizeof ( DWORD );
  79. dwResult = ::RegQueryValueEx ( hKey,
  80. _T("EventLogLevel"),
  81. NULL,
  82. NULL,
  83. reinterpret_cast<LPBYTE>(&dwLogLevel),
  84. &dwLogLevelSize );
  85. if ( ERROR_SUCCESS == dwResult )
  86. {
  87. m_dwMessageLevel = dwLogLevel;
  88. }
  89. ::RegCloseKey ( hKey );
  90. }
  91. ___ASSERT(L"Unable to set message log level !");
  92. m_dwMessageLevel = 1;
  93. return;
  94. }