Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading the Event Log 1

Status
Not open for further replies.

Miker75

Vendor
Jan 7, 2004
35
US
Hi All,

Does anyone know how to read the NT event log? Any help would be greatly appreciated!

Thanks

Michael


HP Certified Technician
 
try opening it with notepad

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
[/b]
Great Delphi Websites faq102-5352
 
Hi there,

try this :

Code:
unit u_eventlog;

interface

uses  SysUtils, Windows;

type
  TEventLog = Class
  public
    procedure Add(EvtType : integer; EvtMsg : string);
  end;

var
  NTEventLog : TEventlog;

implementation


{$R U_EVENTLOG.RES} // include message resource

procedure TEventlog.Add(EvtType : integer; EvtMsg : string);

var Log                        : THandle;
    Category,EventID           : Integer;
    Data,DataSize              : Integer;
    P                          : PChar;

begin
 Log:=OpenEventLog(nil,STR_NAME_APPLICATION);
 if (Log <> 0) then
  begin
   Category:=0;     // no specific category
   EventID := 1000; // only one event defined, message resource has message 1000 included
   Data := 0;       // no data
   DataSize := 0;   // thus size is 0
   P:=Pointer(EvtMsg);
   if not ReportEvent(Log,EvtType,Category,EventID,nil,1,DataSize,@P,@Data) then
    // report any error here to your debugger
   else
   CloseEventLog(Log);
  end
 else Debug.Output('Could not open Windows Application Event log',LVL_NORM);
end;



initialization
 try
  NTEventLog:=TEventLog.Create;
 finally
 end;
finalization
 try
  if Assigned(NTEventLog) then FreeAndNil(NTEventLog);
 finally
 end;
end.

you'll have to remove the '{$R U_EVENTLOG.RES} // include message resource' line because you don't have that file.
it's a message resource forthe eventlog but it works without it


cheers

--------------------------------------
What You See Is What You Get
 
Thanks for the reply whosrdaddy, but what I need is a procedure to read the event log. I believe the code you posted writes to the event log, but does not read it.


HP Certified Technician
 
For as far as I'm aware, the NT Log files are plain text and can be loaded into any TStrings you want.

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
[/b]
Great Delphi Websites faq102-5352
 
Hi Whosrdaddy,

I'd seen that website before but had lost track of it! Thanks very much. From what I've seen so far it's exactly what I need.



HP Certified Technician
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top