Subversion Repositories simple_log_event

Rev

Rev 2 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. unit ViaThinkSoftSimpleLogEvent_Impl;
  2.  
  3. {$WARN SYMBOL_PLATFORM OFF}
  4.  
  5. interface
  6.  
  7. uses
  8.   ComObj, ActiveX, ViaThinkSoftSimpleLogEvent_TLB, StdVcl;
  9.  
  10. type
  11.   TViaThinkSoftSimpleEventLog = class(TAutoObject, IViaThinkSoftSimpleEventLog)
  12.   protected
  13.     procedure LogEvent(const SourceName: WideString; EventType: LogEventType; const LogMsg: WideString);
  14.           safecall;
  15.   end;
  16.  
  17. implementation
  18.  
  19. uses ComServ, Windows;
  20.  
  21. const
  22.   MSG_SUCCESS        = $20000000;
  23.   MSG_INFORMATIONAL  = $60000001;
  24.   MSG_WARNING        = $A0000002;
  25.   MSG_ERROR          = $E0000003;
  26.  
  27. function WriteEventLog(AProvider: string; AEventType: word; AEventId: Cardinal; AEntry: string): boolean;
  28. var
  29.   EventLog: integer;
  30.   P: Pointer;
  31. begin
  32.   Result := False;
  33.   P := PChar(AEntry);
  34.   EventLog := RegisterEventSource(nil, PChar(AProvider));
  35.   if EventLog <> 0 then
  36.   try
  37.     ReportEvent(EventLog, // event log handle
  38.           AEventType,     // event type
  39.           0,              // category zero
  40.           AEventId,       // event identifier
  41.           nil,            // no user security identifier
  42.           1,              // one substitution string
  43.           0,              // no data
  44.           @P,             // pointer to string array
  45.           nil);           // pointer to data
  46.     Result := True;
  47.   finally
  48.     DeregisterEventSource(EventLog);
  49.   end;
  50. end;
  51.  
  52. procedure TViaThinkSoftSimpleEventLog.LogEvent(const SourceName: WideString; EventType: LogEventType;
  53.           const LogMsg: WideString);
  54. begin
  55.   case EventType of
  56.     ViaThinkSoftSimpleLogEvent_TLB.Success:
  57.       WriteEventLog(SourceName, EVENTLOG_SUCCESS,          MSG_SUCCESS,       LogMsg);
  58.     ViaThinkSoftSimpleLogEvent_TLB.Informational:
  59.       WriteEventLog(SourceName, EVENTLOG_INFORMATION_TYPE, MSG_INFORMATIONAL, LogMsg);
  60.     ViaThinkSoftSimpleLogEvent_TLB.Warning:
  61.       WriteEventLog(SourceName, EVENTLOG_WARNING_TYPE,     MSG_WARNING,       LogMsg);
  62.     ViaThinkSoftSimpleLogEvent_TLB.Error:
  63.       WriteEventLog(SourceName, EVENTLOG_ERROR_TYPE,       MSG_ERROR,         LogMsg);
  64.   end;
  65. end;
  66.  
  67. initialization
  68.   TAutoObjectFactory.Create(ComServer, TViaThinkSoftSimpleEventLog, Class_ViaThinkSoftSimpleEventLog,
  69.     ciMultiInstance, tmApartment);
  70. end.
  71.