Any light for TEventLogger?

∥☆過路亽.° 提交于 2019-11-30 14:42:51
Remy Lebeau

TEventLogger is an internal helper class for TService.

You log message using the TService.LogMessage() function, not by calling into TEventLogger directly. The parameters of LogMessage() directly match with the parameters of the Win32 API ReportEvent() function.

Look in the Win32 API documentation for details.

If you are not writing a service application, then you need to call the Win32 API RegisterEventSource() and ReportEvent() functions directly instead.

François

A simple example of an application writing to the event log:

procedure WriteToLog(Msg:string; EventId: Word = 0);
var
  h: THandle;
begin
  h := RegisterEventSource(nil, PChar(Application.ExeName));
  if h > 0 then
  try
    ReportEvent(h, 0, 0, EventId, nil, 1, 0, @Msg, nil);
  finally
    DeregisterEventSource(h);
  end;
end;

procedure TForm7.Button1Click(Sender: TObject);
begin
  WriteToLog('* Blah Blah Blah *');
end;

But beware that not registering the EventID with the system will give this kind of confused Description:

The description for Event ID ( 0 ) in Source ( C:\Documents and Settings\fgaillard\My Documents\RAD Studio\Projects\Project1.exe ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: * Blah Blah Blah *.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!