The Error Log: A New Diagnostic in .NET Compact Framework v2 Service Pack 1

The Error Log: A New Diagnostic in .NET Compact Framework v2 Service Pack 1

Rate This
  • Comments 2
The recent release of Service Pack 1 for the .NET Compact Framework version 2 has added some very useful diagnostic tools.  You may have already read about the .NET Compact Framework Remote Performance Monitor, and have hopefully used it to analyze the performance characteristics of your applications.  Today, I would like to talk about another new diagnostic tool: the error log.

With the addition of support for headless devices, it became apparent that we needed a means for capturing details about unexpected errors.  It is not always feasible to run applications under a debugger, and not all error conditions occur with the consistency that makes them easy to diagnose.  To help address this, the error log was created.  While the error log is typically most useful for headless devices, it is available for all devices running .NET Compact Framework version 2 service pack 1.

Enabling Error Logging
The Error Log is enabled via the device's registry. In my steps, below, I will be using the Remote Registry Editor that is included with Visual Studio 2005. 

WARNING: Using Remote Registry Editor incorrectly can cause serious problems that may require you to hard reset your device. Microsoft cannot guarantee that problems resulting from the incorrect use of Remote Registry Editor can be solved. Use Remote Registry Editor at your own risk.
  1. Start the Remote Registry Editor
    • Open the Start Menu
    • Select All Programs
    • Select Microsoft Visual Studio 2005
    • Select Visual Studio Remote Tools
    • Select Remote Registry Editor
  2. Connect to your device
    • On the Target menu, select Connect
    • Select your device and click OK
  3. Enable diagnostic logging
    • In the left hand pane, expand the device
    • Expand HKEY_LOCAL_MACHINE
    • Expand SOFTWARE
    • Expand Microsoft
    • Expand .NETCompactFramework
    • Expand Diagnostics
      If this key does not exist, you will need to create it
      • Right click on .NETCompactFramework
      • Select New > Key Type "Diagnostics" (without quotes)
      • Click OK
    • Expand Logging
      If this key does not exist, you will need to create it
      • Right click on Diagnostics
      • Select New > Key
      • Type "Logging" (without quotes)
      • Click OK
    • Set the value of Enabled to 1
      If this value does not exist, you will need to create it
      • Right click on Logging
      • Select New > DWORD Value
      • Set the Name to "Enabled" (without quotes)
      • Set the value to 1
      • Click OK
  4. Enable error logging
    • In the Logging key (from step 3) expand Error
      If this key does not exist, you will need to create it
      • Right click on Logging
      • Select New > Key
      • Type "Error" (without quotes)
      • Click OK
    • Set the value of Enabled to 1
      If this value does not exist, you will need to create it
      • Right click on Error
      • Select New > DWORD Value
      • Set the Name to "Enabled" (without quotes)
      • Set the value to 1
      • Click OK

To disable the Error Log, follow the above steps and set the value of Enabled to 0. To disable all logging, follow only steps 1-3, and set the value of Enabled to 0.

TIP: Set the value of UseApp (under Logging) to 1 to enable application specific log files.


Using the Error Log
To demonstrate the error log, I created a very simple application that encounters an unhandled exception.  After the application exits (is terminated by clicking the Quit button), the error log file will be created.

NOTE: On headless devices, error dialogs are dismissed automatically using the default button.

After opening the log file, we can see the unhandled exception.

Caption: UnhandledException.exe
Title : Error
Text : An unexpected error has occurred in UnhandledException.exe.
Select Quit and then restart this program, or select Details for more information.

Cannot perform requested task at this time
Details: (null)


On devices with display capabilities, clicking the Details button will result in the following additional data being present in the error log file.

Caption: UnhandledException.exe
Title : Error
Text : UnhandledException.exe
ApplicationException
Cannot perform requested task at this time

at UnhandledException.Program.PerformTask()
at UnhandledException.Program.Main()

Details: (null)


As we can see, the new error log feature allows unexpected errors can now be captured in the field, without requiring users to copy large amounts of data manually from the device. 

Enjoy!
-- DK

Disclaimer(s): This posting is provided "AS IS" with no warranties, and confers no rights.

  • With the addition of support for headless devices, it became apparent that we needed a means for capturing...
  • I started this series last year and thought I would continue the tradition with my best of 2006 collection.

Page 1 of 1 (2 items)