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.

161 lines
6.5 KiB

  1. /*************************************************************************
  2. * Microsoft Windows NT *
  3. * *
  4. * Copyright(c) Microsoft Corp., 1994 *
  5. * *
  6. * Revision History: *
  7. * *
  8. * Jan. 29,94 Koti Created *
  9. * *
  10. * Description: *
  11. * *
  12. * This file contains the functions that invoke all the EventLogging *
  13. * related functions. *
  14. * *
  15. *************************************************************************/
  16. #include "lpd.h"
  17. /*****************************************************************************
  18. * *
  19. * InitLogging(): *
  20. * This function prepares for future logging by registersing. *
  21. * *
  22. * Returns: *
  23. * TRUE if it succeeded *
  24. * FALSE if it didn't *
  25. * *
  26. * Parameters: *
  27. * None *
  28. * *
  29. * History: *
  30. * Jan.29, 94 Koti Created *
  31. * *
  32. *****************************************************************************/
  33. BOOL InitLogging( VOID )
  34. {
  35. hLogHandleGLB = RegisterEventSource( NULL, LPD_SERVICE_NAME );
  36. if ( hLogHandleGLB == (HANDLE)NULL )
  37. {
  38. LPD_DEBUG( "InitLogging(): RegisterEventSource failed\n" );
  39. return( FALSE );
  40. }
  41. return( TRUE );
  42. } // end InitLogging()
  43. /*****************************************************************************
  44. * *
  45. * LpdReportEvent(): *
  46. * This is the function where logging of events actually takes place. *
  47. * *
  48. * Returns: *
  49. * Nothing *
  50. * *
  51. * Parameters: *
  52. * idMessage (IN): ID of the message to be put in the log file *
  53. * wNumStrings (IN): number of strings in the "variable parts" of message *
  54. * aszStrings (IN): the "variable parts" of the message *
  55. * dwErrcode (IN): error code for the (failed) event *
  56. * *
  57. * History: *
  58. * Jan.29, 94 Koti Created *
  59. * *
  60. *****************************************************************************/
  61. VOID
  62. LpdReportEvent( DWORD idMessage, WORD wNumStrings,
  63. CHAR *aszStrings[], DWORD dwErrcode )
  64. {
  65. WORD wType;
  66. DWORD cbRawData=0;
  67. PVOID pRawData=NULL;
  68. if ( hLogHandleGLB == NULL )
  69. {
  70. DEBUG_PRINT (("LpdReportEvent(): Log handle is NULL! EventId <0x%x> not logged\n", idMessage));
  71. return;
  72. }
  73. if ( NT_INFORMATION( idMessage) )
  74. {
  75. wType = EVENTLOG_INFORMATION_TYPE;
  76. }
  77. else if ( NT_WARNING( idMessage) )
  78. {
  79. wType = EVENTLOG_WARNING_TYPE;
  80. }
  81. else if ( NT_ERROR( idMessage) )
  82. {
  83. wType = EVENTLOG_ERROR_TYPE;
  84. }
  85. else
  86. {
  87. LPD_DEBUG( "LpdReportEvent(): Unknown type of error message\n" );
  88. wType = EVENTLOG_ERROR_TYPE;
  89. }
  90. if ( dwErrcode != 0 )
  91. {
  92. pRawData = &dwErrcode;
  93. cbRawData = sizeof( dwErrcode );
  94. }
  95. ReportEvent( hLogHandleGLB, wType, 0, idMessage, NULL, wNumStrings,
  96. cbRawData, (LPCTSTR *)aszStrings, pRawData );
  97. return;
  98. } // end LpdReportEvent()
  99. /*****************************************************************************
  100. * *
  101. * EndLogging(): *
  102. * This function ends logging by deregistering the handle. *
  103. * *
  104. * Returns: *
  105. * Nothing. *
  106. * *
  107. * Parameters: *
  108. * None *
  109. * *
  110. * History: *
  111. * Jan.29, 94 Koti Created *
  112. * *
  113. *****************************************************************************/
  114. VOID EndLogging( VOID )
  115. {
  116. if ( hLogHandleGLB == NULL )
  117. {
  118. LPD_DEBUG( "EndLogging(): Log handle is NULL!\n" );
  119. return;
  120. }
  121. DeregisterEventSource( hLogHandleGLB );
  122. return;
  123. } // end EndLogging()