• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 847
  • Last Modified:

Event logging

Hi

I've been looking at adding event logging into one of my projects to enhance my ability to debug problems. There seems to be several ways or at least several articles with various amounts of code attached suggesting how to acheive this.

I have been searching this site and using articles such as:
http://www.thedelphimagazine.com/samples/1655/article.htm
http://www.dragonsoftru.com/articles/EventLog.html

So far I have found that using:

var
  Form1: TForm1;
 EventLog : Thandle;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
VAR MyMsg:Array[0..2] Of PChar;
begin
MyMsg[0]:= 'A test event message';
ReportEvent(EventLog,EVENTLOG_INFORMATION_TYPE,0,0,nil,1,0,@MyMsg,nil);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
EventLog := RegisterEventSource(nil,PChar('Project1'));
end;

Works and adds an event that looks like:
Event Type:      Information
Event Source:      Project1
Event Category:      None
Event ID:      0
Date:            25/05/2006
Time:            10:37:02
User:            N/A
Computer:      STUDY-2
Description:
The description for Event ID ( 0 ) in Source ( Project1 ) 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: A test event message.

Am i correct in understanding that the only way to replace:

'The description for Event ID ( 0 ) in Source ( Project1 ) 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.'

I need to add registry entires, and a dll containing  a .res file?

The line 'The description for Event ID ( 0 ) in Source ( Project1 ) cannot be found.' seems to suggest that the information could be 'in source' so is there an easier way?

Thanks
Pete

 
0
PeteMulford
Asked:
PeteMulford
  • 4
  • 3
1 Solution
 
JDSkinnerCommented:
Have a look at this component
http://www.eurekalog.com/details.php
0
 
PeteMulfordAuthor Commented:
Hi

Thanks, I  already use Madshi's 'Mad except' component which I find great, and his support is absolutly excellent.

I wanted to log succesfull operations as well as potential errors.

Pete
0
 
Russell LibbySoftware Engineer, Advisory Commented:
Pete,

The message resource file(s) can be created for a delphi dll/app, but the mc.exe compiler is required (message compiler, normally found on VStudio installs). This compiler can be obtained by downloading the MS Platform SDK. The format of the message text file (*.mc text file) is:

--- example from my own sources ---
MessageId=100
SymbolicName=HS_INSTALLED
Language=English
The %1 service was installed.
.

MessageId=
SymbolicName=HS_REMOVED
Language=English
The %1 service was removed.
.

MessageId=
SymbolicName=HS_NOTREMOVED
Language=English
The %1 service could not be removed.
.

MessageId=
SymbolicName=HS_CTRLHANDLERNOTINSTALLED
Language=English
The %1 service control handler could not be installed.
.

MessageId=
SymbolicName=HS_FAILEDINIT
Language=English
The %1 service initialization process failed.
.

MessageId=
SymbolicName=HS_STARTED
Language=English
The %1 service was started.
.

MessageId=
SymbolicName=HS_STOPPED
Language=English
The %1 service was stopped.
.
--- end example ---

A good writeup for the process of message creation/compiling can be found here:

http://www.ftponline.com/archives/premier/mgznarch/vbpj/2001/09sep01/lj0109/lj0109-2.asp

But I can personally state that the process is a real pain (achievable, but a  pain).

Hope this helps,
Russell
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
PeteMulfordAuthor Commented:
Hi

This is where I get a bit confused! Am I correct in thinking you are suggesting the first method in http://www.thedelphimagazine.com/samples/1655/article.htm ie
"Microsoft supplies a program called MC.EXE, which is used to compile message resource definition script files into binary resource files. The binary resource can then be linked into a Delphi- compatible resource file." ?

because that article goes on to say:
"Borland does not supply any tools that support the creation\ editing of Message Tables, but Colin Wilson has created a very nice freeware resource editor called PEResourceExplorer.exe, which I suggest everyone download from his website at www. wilsonc.demon.co.uk/delphi.htm.

Using PEResourceExplorer.exe you can easily create a new Message Table and then save it to disk as a Windows resource file (that is, a .res file). See MSDN online for a complete explanation of the strings required for event logging. "

But i tried just adding {$R elsxm.res} (where elsxm was the name I used for the table I made, but it didnt appear to work.

I'm obvioulsy not understanding something!

Pete
0
 
Russell LibbySoftware Engineer, Advisory Commented:

Wish I had known about Colin's utility when I was working on my project..... the mc.exe process was not the most pleasant experience ;-). And that was what I was suggesting (been there, and it works, though not the easiest), but I did not realize someone had written a utility to create the resources directly.

As to the resource not working, I can't really say without looking at your code. Be aware that the event ID's need to match what you have in your table, the event resource info needs to be placed in the registry, etc, etc. I would suggest testing the simple project that is desribed in the article first, just to confirm that the process works and that you are familiar with the steps. Alternately, you can post the code you are using as well as the table message id's, and I can look at that as well

Russell
0
 
PeteMulfordAuthor Commented:
Hi

It seems a really good program.

But what i didnt quite understand was whether I needed the code to add the info to registry as the line 'The description for Event ID ( 0 ) in Source ( Project1 ) cannot be found.' seems to suggest that the information could be 'in source' rather than in the registry?

Admittedly i didnt add the code to deal with the reg, and it didnt work....

Pete
0
 
Russell LibbySoftware Engineer, Advisory Commented:
Pete,

It works like this: You create an exe/dll that contains the resources (table of messages, where the event id = id of message in the table) You "register" this message source by updating the registry as stated in the article, except the source name is 'Project1' in your example. When the event log goes to obtain a message for an event from your source (Project1), it looks up the message handler for the source of the event (in the registry), then attempts to obtain the message resource using the category and event id.

Without the registry part of things, the event log viewer has no idea where to obtain the message resources. if you check out my web site (listed in my profile), you will find source for an event log viewer class, which may help you understand what the event log viewer does to get the message source (relevant code is in LoadResStrs).

Russell
0
 
PeteMulfordAuthor Commented:
Thanks for the explanation Russel :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now