-
June 7th, 2011, 12:54 AM
#1
Application errors shown in event viewer
How do you make messages from when you run your code land in windows log>Application section in the Event Viewer (that comes with windows)? I noticed there're error messages and information messages. How do you make your message error and information?
-
June 7th, 2011, 01:19 AM
#2
Re: Application errors shown in event viewer
It's not a very easy task but you can start digging in MSDN Event Logging documentation.
-
June 7th, 2011, 09:28 AM
#3
Re: Application errors shown in event viewer
As ovidiucucu says, it's not an easy task to use the Windows event logging api. That's why I wrote my own event logging mechanism. Surprisingly, it's not difficult. I exported a method that uses IPC to post an event to a separate event server (ie. process) that runs in the background. Our programmers can post any event they'd like to the server.
Gort...Klaatu, Barada Nikto!
-
June 7th, 2011, 03:32 PM
#4
Re: Application errors shown in event viewer
Mike Harnad, how do you view the events? do you have your own program that retrieves the messages from your server, or does the message eventually land in Event log?
-
June 7th, 2011, 03:39 PM
#5
Re: Application errors shown in event viewer
luk, you guessed right. The server that runs in the background is accessible from the task bar. It has a menu of options, one of which is to view our event log. Note: the event messages are not written to the Windows event log. We write them out to an xml file when our event server closes.
Gort...Klaatu, Barada Nikto!
-
June 8th, 2011, 01:39 AM
#6
Re: Application errors shown in event viewer
Returning a little to Windows Event Log system.
Basically, to add a record in "Application" event log you just have to call ReportEvent.
Here is a simplified demo example:
Code:
#include <windows.h>
int main()
{
LPCWSTR lpSourceName = L"My Cool Application";
DWORD dwEventID = 123;
HANDLE hEventLog = ::RegisterEventSourceW(NULL, lpSourceName);
if(NULL != hEventLog)
{
::ReportEventW(
hEventLog, // handle to event log
EVENTLOG_ERROR_TYPE, // event type
0, // event category
dwEventID, // event identifier
NULL, // user security identifier
0, // number of strings to merge
0, // size of binary data
NULL, // array of strings to merge
NULL); // binary data buffer
::DeregisterEventSource(hEventLog);
}
return 0;
}
If run the above program then open Event Viewer shipped with Windows, you can see a record of type "Error", having "My Cool Application" source and identifier "123" and timestamp "...".
Till now, everything is more than easy.
However this is not enough because usually you want more info like event description, category, and so on.
For that purpose, you need to add in registy a key for your own application event source, which tells about your application message file.
This message file is usually a resource-only DLL having a message-table resource (RT_MESSAGETABLE).
As I said in my first post, this is not a very easy task.
However, it's not impossible.
Windows event log system is well documented and just need a little sweat to understand it.
Last edited by ovidiucucu; June 8th, 2011 at 01:41 AM.
-
June 9th, 2011, 01:17 PM
#7
Re: Application errors shown in event viewer
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|