Retrofitting Windows Event Log to a Delphi 5 app

后端 未结 4 1896
慢半拍i
慢半拍i 2021-01-01 04:56

I\'m looking for a (fairly pain-free) means of adding some Windows Application Event-Log support to a small legacy Delphi 5 application. We just want it to log when it start

4条回答
  •  暖寄归人
    2021-01-01 05:57

    For simple event logging in D5, I have used the following code to add messages to the Applications log.

    • Add "SvcMgr" to the uses clause
    • Use this code to add your text message and an ID number (last parameter on LogMessage lines)

      with TEventLogger.create('My Application Name') do
      begin
        try
          LogMessage('Information Message!', EVENTLOG_INFORMATION_TYPE, 0, 1);
          LogMessage('Error Message!', EVENTLOG_ERROR_TYPE, 0, 2);
          LogMessage('Warning Message!', EVENTLOG_WARNING_TYPE, 0, 3);
          LogMessage('Audit Success Message!', EVENTLOG_AUDIT_SUCCESS, 0, 4);
          LogMessage('Audit Failure Message!', EVENTLOG_AUDIT_FAILURE, 0, 5);
        finally
          free;
        end;
      end;
      

提交回复
热议问题