Click to See Complete Forum and Search --> : How to write to Windows event log
garage
July 4th, 2007, 01:02 AM
Hi,
I am using C++ on Vista.
Can anyone suggest me the steps to write to the Windows event log.
What will be the value in 1st parameter of EventRegister(). Where from I will get the GUID. My one is not COM based application. 100% Windows application w/o any use of MFC also.
Can anyone direct me to any sample code ?
Thanks,
garage
Ejaz
July 4th, 2007, 03:01 AM
Take a look at the followings.
Registering an Event Trace Provider (http://msdn2.microsoft.com/en-US/library/aa364104.aspx)
How to log a crimson event to the custom log (for parental controls) (http://blogs.technet.com/david_bennett/archive/2006/08/28/452296.aspx)
garage
July 4th, 2007, 05:21 AM
Thanks Ejaz for the information.
As I am working on Vista, so need to follow manifest-based process. But, at this point my biggest problem is that Iam unable to find the GUID in my application and hence not able to proceed with EventRegister().
I don't have any idea also where to look for this info ? Looking for some direction.
Thanks,
garage
garage
July 5th, 2007, 01:19 AM
I am not able to find the GUID inside my application.
Can anybody point me what exactly I have to do.
My one is C++ desktop application and I need to write to WIndows Event log. Am using Vista. I need to use EventRegister() as a first step and am unable to find that.
Ejaz
July 5th, 2007, 01:31 AM
As per MSDN
The GUID is defined in the header file generated from the manifest.
Does Programming the Windows Vista Event Log (http://www.developer.com/net/cplus/print.php/3624581) helps you in doing this? It shows how to use guid from manifest file to register event.
garage
July 5th, 2007, 02:26 AM
Thanks Ejaz. That link provides more information.
Just to share my understanding and get your views, here is what I learnt.
- My application does not take care of Win event logging as of now.
- So, I need to create an XML (manifest) file and compile it using mc.exe
to get the header file with GUID and also one .rc file.
- Add these files to my project and go ahead with EventRegistration and
do your task. Then install the .xml file to display the event log in the Event
Viewer.
Here I have one question :
Generation of GUID is one time job. If any other developer on his machine use mc.exe to compile the manifest file again then what will be the impact ? I think new GUID will get created. Your comment please !
As I understand, one needs to install the XML file in every machine to display the event log for your event in Event viewer. Comment please
Thank you again for your help in and looking forward for your suggestion.
Thanks,
garage
Ejaz
July 5th, 2007, 03:02 AM
Well, I never done any event logging myself, therefore, my opinion will be based upon theory :)
GUID is just a 128-bit integer (16 bytes) that can be used across all computers and networks wherever a unique identifier is required with very low probability of being duplicated. Therefore, the manifest file created once with the guid should serve the purpose at other machines as well.
For deployment, the manifest file needs to be registered by using the command wevtutil:
wevtutil install-manifest manifestFileName.xml
The wevtutil utility, which ships with Windows Vista, will parse the manifest and add the required settings to the Vista Event Log.
garage
July 19th, 2007, 02:09 AM
Here is some confusion regarding GUID. Initially, I thought when the .xml file will be compiled using message compiler, GUID will be generated and can be found in .h file. But, when I downloaded the sample code in the link you provided (Programming the Windows Vista Event Log) and opened the manifest.xml file I found the following inside the file :
<provider name="Microsoft-Windows-EventLogSamplePublisher"
guid="{1db28f2e-8f80-4027-8c5a-a11f7f10f62d}"
symbol="MICROSOFT_SAMPLE_PUBLISHER"
resourceFileName="C:\temp\Publisher.exe"
messageFileName="C:\temp\Publisher.exe">
So where from that guid generated and is part of .xml file ? So, my understanding got changed now unable to find a way out to get the GUID which is very much essential for writing to Windows event log. Need to pass that GUID to EventRegister() API.
My one is pure C++ application. Can anyone suggest me a way to resolve this problem ?
Regards,
Garage
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.