> Has anybody got an example of logging NT events (plus associated tricks
> and traps).
>
> e.g. We have an OLE object running under IIS4, accessed from web pages
> using ASP, and we want to log any exceptions as NT events for later
> examination.
I have event logging routines as part of NT service wizard.
Here is some code fragments that should put you in right direction.
Bits for setting up acesss.
Const
EVENTLOG_KEY =
'SYSTEM\CurrentControlSet\Services\EventLog\Application\';
...
{Set up Event Log access}
LogKey := EVENTLOG_KEY + ServiceName;
if RegCreateKey(HKEY_LOCAL_MACHINE, @LogKey[1], hLogKey) <>
ERROR_SUCCESS then
raise Exception.Create('Unable to create registry key: Error ' +
IntToStr(GetLastError));
if RegSetValueEx(hLogKey, 'EventMessageFile', 0, REG_EXPAND_SZ,
@FileName[0],
StrLen(FileName) + 1) <> ERROR_SUCCESS then
raise Exception.Create('Unable to create registry key: Error ' +
IntToStr(GetLastError));
{Bit mask of message types supported}
dwData := EVENTLOG_ERROR_TYPE or
EVENTLOG_WARNING_TYPE or
EVENTLOG_INFORMATION_TYPE;
RegSetValueEx(hLogKey, 'TypesSupported', 0, REG_DWORD, @dwData,
SizeOf(DWORD));
RegCloseKey(hLogKey);
procedure TNTService.LogEvent(dwType: DWORD; dwID : DWORD; Arg1,
Arg2, Arg3: String);
var
I : word;
P : PAnsiChar;
begin
I := 0;
if Arg1 <> '' then begin
if Assigned(sMsgArray[I]) then
StrDispose(sMsgArray[I]);
sMsgArray[I] := StrAlloc(Length(Arg1) + 1);
StrPCopy(sMsgArray[I], Arg1);
Inc(I);
end;
if Arg2 <> '' then begin
if Assigned(sMsgArray[I]) then
StrDispose(sMsgArray[I]);
sMsgArray[I] := StrAlloc(Length(Arg2) + 1);
StrPCopy(sMsgArray[I], Arg2);
Inc(I);
end;
if Arg3 <> '' then begin
if Assigned(sMsgArray[I]) then
StrDispose(sMsgArray[I]);
sMsgArray[I] := StrAlloc(Length(Arg3) + 1);
StrPCopy(sMsgArray[I], Arg3);
Inc(I);
end;
P := sMsgArray[0];
{Make sure event source is registered}
if shEventSource = 0 then
shEventSource := RegisterEventSource(nil, @sServiceName[1]);
if shEventSource > 0 then
Begin
If Not ReportEvent(shEventSource, dwType, 0, dwID, nil,
I, 0, @sMsgArray, nil) then
istat := Getlasterror;
end;
end;
----------------------------------------------------------
Phil Scadden, Institute of Geological and Nuclear Sciences
PO Box 30368, Lower Hutt, New Zealand
Ph +64 4 5704821, fax +64 4 5704603
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz