<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Programming tidbits: store &amp; retrieve : Diagnostics</title><link>http://blogs.msdn.com/oanapl/archive/tags/Diagnostics/default.aspx</link><description>Tags: Diagnostics</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Windows Error Reporting (WER) for developers</title><link>http://blogs.msdn.com/oanapl/archive/2009/01/28/windows-error-reporting-wer-for-developers.aspx</link><pubDate>Wed, 28 Jan 2009 07:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9379777</guid><dc:creator>OanaPlaton</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/oanapl/comments/9379777.aspx</comments><wfw:commentRss>http://blogs.msdn.com/oanapl/commentrss.aspx?PostID=9379777</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Windows Error Reporting is the replacement for Dr. Watson on OSs newer that Windows XP. It monitors failures and collects useful information that can be sent to a server to be analyzed (if the user allows it). This feature helped Microsoft to fix a lot of bugs – due to the reports received, Microsoft was able to prioritize bugs (based on the biggest number of hits or other severity measures) and to solve a lot of problems. What is really cool is that any developer can request the reports for his/her product. &lt;SPAN style="mso-bidi-font-weight: bold"&gt;From&lt;B&gt; &lt;/B&gt;&lt;A href="http://www.microsoft.com/whdc/maintain/WERHelp.mspx" mce_href="http://www.microsoft.com/whdc/maintain/WERHelp.mspx"&gt;Bill Gates at PDC 2003&lt;/A&gt;&lt;B&gt;: &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;I&gt;“..whenever an application or the system malfunctions, you get the ability to send a report back to Microsoft. We get a lot of those reports, and we've created very good data-management systems to go in and look at those things, and therefore understand what drivers aren't reliable. We allow anyone who has an application that runs on Windows to sign up and get the reports that relate to their application, and we've got winqual.microsoft.com where people can do that.&lt;/I&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;”&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;FONT face=Calibri size=3&gt;Here’s how WER works: when a process crashes, WER collects the data and sends it to a server (if the user allows it; by default WER asks for consent). For non-Microsoft programs, this server is &lt;/FONT&gt;&lt;A href="https://winqual.microsoft.com/" mce_href="https://winqual.microsoft.com/"&gt;&lt;FONT face=Calibri size=3&gt;Winqual&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; (Windows Quality Online Services). On the server side: Based on the parameters of the crash, a bucket is created to hold the new error, or the report is added to an already existing bucket (which means someone met this issue before). A developer can analyze the failure; if a solution can’t be found based on the collected data, he/she can request additional information (a dump, registry key values etc). Also, he/she can add a message explaining the failure. When an instance of the same type of crash happens, the server will display the message the developer set and will ask for the additional information if necessary. If the developer finds a solution, at the next crash the server can &lt;/FONT&gt;&lt;A href="http://www.microsoft.com/whdc/maintain/WER/ErrSolution.mspx" mce_href="http://www.microsoft.com/whdc/maintain/WER/ErrSolution.mspx"&gt;&lt;FONT face=Calibri size=3&gt;provide solutions&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; (see diagram below). Read more about &lt;/FONT&gt;&lt;A href="http://www.microsoft.com/whdc/maintain/WER/ErrClass.mspx" mce_href="http://www.microsoft.com/whdc/maintain/WER/ErrClass.mspx"&gt;&lt;FONT face=Calibri size=3&gt;error reports collection and classification&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;IMG title="WER Flow" style="WIDTH: 477px; HEIGHT: 480px" height=480 alt="WER Flow" src="http://blogs.msdn.com/photos/oanapl/images/9379763/original.aspx" width=477 mce_src="http://blogs.msdn.com/photos/oanapl/images/9379763/original.aspx"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;On Vista and above, the user with the crashed program can go to Control Panel -&amp;gt; Problem Reports and Solutions (start wercon.exe) to see what failures happened on the machine.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;IMG title="Problem Reports and Solutions" style="WIDTH: 456px; HEIGHT: 282px" height=282 alt="Problem Reports and Solutions" src="http://blogs.msdn.com/photos/oanapl/images/9379789/original.aspx" width=456 mce_src="http://blogs.msdn.com/photos/oanapl/images/9379789/original.aspx"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Here, you&amp;nbsp;can check for solutionsand see identified problems.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&lt;IMG title="Problem Reports and solutions - View problems" style="WIDTH: 640px; HEIGHT: 195px" height=195 alt="Problem Reports and solutions - View problems" src="http://blogs.msdn.com/photos/oanapl/images/9379769/original.aspx" width=640 mce_src="http://blogs.msdn.com/photos/oanapl/images/9379769/original.aspx"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;You can look at the parameters for each issue and see the bucket in which the report was categorized.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;IMG title="Problem Reports and Solutions - Report Parameters" style="WIDTH: 640px; HEIGHT: 480px" height=480 alt="Problem Reports and Solutions - Report Parameters" src="http://blogs.msdn.com/photos/oanapl/images/9379771/original.aspx" width=640 mce_src="http://blogs.msdn.com/photos/oanapl/images/9379771/original.aspx"&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;FONT face=Calibri size=3&gt;As a developer, you can go to Winqual and register to receive reports for failures. But there are other ways you can take advantage of WER. You can configure WER to send the reports to one of your servers, so you can take a look at them directly. For example, imagine you have a couple of machines you want to monitor. You can use &lt;/FONT&gt;&lt;A href="http://www.microsoft.com/systemcenter/operationsmanager/en/us/default.aspx" mce_href="http://www.microsoft.com/systemcenter/operationsmanager/en/us/default.aspx"&gt;&lt;FONT face=Calibri size=3&gt;System Center Operations Manager&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; (SCOM) with &lt;/FONT&gt;&lt;A href="http://technet.microsoft.com/en-us/library/bb309443.aspx" mce_href="http://technet.microsoft.com/en-us/library/bb309443.aspx"&gt;&lt;FONT face=Calibri size=3&gt;Agenteless Error Monitoring&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; (AEM) to transfer all reports to a monitoring server instead of sending them to Winqual. You don’t even have to use Active Directory integration and group policies, but you can manually configure the &lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/bb513638(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb513638(VS.85).aspx"&gt;&lt;FONT face=Calibri size=3&gt;WER registry keys&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt; to specify the CorporateWERServer (with the port and the security options you prefer).&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Another way to take advantage of WER is to save the reports locally. For the rest of the article, I will assume that WER is enables (default setting). &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Like I said, WER tries to collect as little data as possible and asks for more only if necessary. But this behavior can be configured. If you need a dump collected at every crash, you can set HKEY_CURRENT_USER\Software\Microsoft\Windows\Windows Error Reporting\ForceQueue to 1 (or the HKLM\Software\Microsoft\Windows\Windows Error Reporting\ForceQueue=1, to apply the settings globally).This will force a dump to be generated and included in the report. The reports are usually saved at %localAppData%\Microsoft\Windows\WER, in 2 directories: ReportArchive, when a server is available or ReportQueue, when the server is not available. From here, the data is transferred to the server. Another way to look at the contents of the generated report, is to use wercon.exe (as explained above). If you want to keep the data locally, just set the server to a non-existing machine (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\CorporateWERServer=NonExistingServer). &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;FONT face=Calibri size=3&gt;Now what if you want to generate reports on different conditions that a crash? Maybe you are monitoring the event log or some performance counters like CPU or memory and you want to see what happens when the conditions are violated. Or you want to generate more data than just a dump (for example, your applications has a trace file you want to save, or you want to copy event log entries etc)? Well, you’re in luck, because WER has &lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/bb513636(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb513636(VS.85).aspx"&gt;&lt;FONT face=Calibri size=3&gt;API&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt; you can use. With this API, whenever your desired conditions are met, you can:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpFirst style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-style: italic"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;FONT face=Calibri size=3&gt;Create a report with &lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/bb513625(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb513625(VS.85).aspx"&gt;&lt;B&gt;&lt;FONT face=Calibri color=#0000ff size=3&gt;WerReportCreate&lt;/FONT&gt;&lt;/B&gt;&lt;/A&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-style: italic"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;FONT face=Calibri size=3&gt;Take a dump with &lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/bb513622(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb513622(VS.85).aspx"&gt;&lt;B&gt;&lt;FONT face=Calibri size=3&gt;WerReportAddDump&lt;/FONT&gt;&lt;/B&gt;&lt;/A&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-style: italic"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;FONT face=Calibri size=3&gt;Add other files of interest with &lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/bb513623(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb513623(VS.85).aspx"&gt;&lt;B&gt;&lt;FONT face=Calibri color=#0000ff size=3&gt;WerReportAddFile&lt;/FONT&gt;&lt;/B&gt;&lt;/A&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-style: italic"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Set up to 10 parameters that can be used to categorize the failure (the faulting program, the faulting function, stack trace, whatever you consider useful to investigate the issue)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpLast style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-style: italic"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;-&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-style: italic"&gt;&lt;FONT face=Calibri size=3&gt;Close and submit the report with &lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/bb513628(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb513628(VS.85).aspx"&gt;&lt;B&gt;&lt;FONT face=Calibri color=#0000ff size=3&gt;WerReportSubmit&lt;/FONT&gt;&lt;/B&gt;&lt;/A&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;One thing you must keep in mind (and this was not obvious to me at all, I got burned actually) is that WerReportAddDump will suspend the threads one by one when taking a dump. That can’t ensure a consistent view of the memory - a thread can be suspended and then while the next one is suspended can change memory or do other damage; this is especially troublesome if your application has a lot of threads. It’s your responsibility to suspend all threads if you need a consistent view. Also, it is a good idea to call this function out of process.&lt;/FONT&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 11pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-fareast-font-family: Calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;Ok, so now you know how to use WER to always generate dumps on failure, send the reports to a server you specify or queue them locally and to build custom reports. Hope you'll find this info useful to debug and monitor issues related to your apps.&lt;/SPAN&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9379777" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/oanapl/archive/tags/Diagnostics/default.aspx">Diagnostics</category><category domain="http://blogs.msdn.com/oanapl/archive/tags/WER/default.aspx">WER</category></item></channel></rss>