The Moth
Developer, Former MVP, now at Microsoft - Best of
2004
,
2005
,
2006
,
2007
,
2008
,
2009
« CF article on MSDN mag
|
Home
|
Reading books »
Debug.WriteLine
Wed, November 17, 2004, 09:58 AM under
MobileAndEmbedded
One of the first complaints .NET desktop developers have when targeting the CF v1.0 for the first time is "
Debug.WriteLine doesn't work
".
The fact is that with Smart Device projects the debug output does not come back to Visual Studio; rather it goes to the console on the target device. It is true that Debug/Console WriteLine statements do not appear when debugging on PocketPC devices/emulators, but this is not a CF issue; it is rather due to a lack of console on the PPC platform. Debugging a CF app on the CE emulator or a CE-based device results in the display of a console window
on the target
with the debug statements. Note that even on a CE device, if you build it without the console (cmd.exe) you will get no debug output (I should know, since I have accidentally run into that scenario when we ported from CE 4.1 to 4.2, but I digress).
So what can you do about it? There are a number of options and I will link to them in this entry, ready for the next time someone asks
Add a console to the target, e.g.
this one
Redirect the output to a file, e.g.
like this
Send the output back to the dev machine, e.g.
like that
or
that
Of course you could switch away from using System.Diagnostics directly and write your own logging framework. As you'd expect, this has been done before and there are a number of 3rd-party solutions, some of which may be too simple and others too complex for your project's liking. So here are some options:
MSFT offer the
Enterprise Instrumentation Framework
, but I doubt it supports the CF.
I have met references to
log4net
a few times, but
I don't think it supports the CF
it is under the Apache license.
Over at the useful openetcf there is a
logging system
, but I must admit not having played with it, and I don't know if it works on the desktop
For my own projects (CF and full Fx), I have been using a class I wrote years ago. Features include:
1. Just one file to include in your project. Only one class with static methods.
2. Use of the standard Debug class internally, so the output goes to VS console (desktop) or device's console (CF)
3. CSV formatted output (inserting additional info such as timestamp etc.)
4. Redirection of output to a HyperTerminal on the desktop, when running a debug OS on your CE target
5. Support of 3 severity levels (Info, Warning/Assert and Error). Auto detectable based on project configuration (e.g. DEBUG, TRACE)
6. Further configuration available via TraceSwitch (both platforms) and optionally via config file (desktop only)
7. Writing to a file (on both platforms, path and name computed internally also take into account COM Interop clients)
8. Rolling of the filename, thus preserving debug info between different runs of the application
Feel free to play with
it
.
If you are interested in the subject of tracing, you will love a new feature in Whidbey: Tracepoints. I was going to write about it, but many others have done so already [
1
,
2
,
3
]
UPDATE:
Visual Studio 2005 (and .NET Compact Framework v2.0) support Debug.WriteLine
Comments [0]
|
Permalink
Comments are closed.
About
My team's page on MSDN
Subscribe
Contact Form
My screencasts on channel9
Tags
AboutPresenting (5)
Blogging (7)
Career (5)
Communication (5)
dotNET (120)
Events (93)
GPGPU (2)
HPC (6)
IE7 RSS (6)
Links (129)
LINQ (23)
MobileAndEmbedded (148)
Orcas (128)
ParallelComputing (63)
Personal (32)
Random (42)
SideShow (12)
Silverlight (17)
SoftwareProcess (3)
UAC (14)
UserInterfaceDesign (5)
Vista (84)
VisualStudio (112)
Whidbey (31)
Windows (90)
WindowsServer2008 (3)
Latest Posts
Parallel Computing Platform Developer Lab
Slides and code for MPI Cluster Debugger
DirectCompute
GPGPU
Code for Parallelism Features Tour
Managed code and the Shell – Do?
Dev Lead Job opening on my team
Best of "The Moth" 2009
Bug Triage
Parallel Computing Features Tour in VS2010
MPI Cluster Debugger launch integration in VS2010
Parallel Debugging
"Parallel Programming Talk" show
Message Passing Interface (MPI)
Windows HPC Server links
Extension Manager in Visual Studio 2010
Core debugger enhancements in VS2010
Dump debugging with Parallel Stacks
Slides for Parallel Debugging windows
MPI Project Template for VS2010
Archives
March, 2010 (2)
February, 2010 (3)
January, 2010 (3)
December, 2009 (1)
November, 2009 (11)
October, 2009 (12)
September, 2009 (1)
August, 2009 (6)
July, 2009 (5)
June, 2009 (3)
May, 2009 (7)
April, 2009 (5)
March, 2009 (3)
February, 2009 (4)
January, 2009 (6)
December, 2008 (3)
November, 2008 (12)
October, 2008 (6)
September, 2008 (9)
August, 2008 (5)
July, 2008 (5)
June, 2008 (8)
May, 2008 (18)
April, 2008 (11)
March, 2008 (13)
February, 2008 (17)
January, 2008 (15)
December, 2007 (20)
November, 2007 (25)
October, 2007 (19)
September, 2007 (11)
August, 2007 (31)
July, 2007 (24)
June, 2007 (19)
May, 2007 (24)
April, 2007 (18)
March, 2007 (35)
February, 2007 (34)
January, 2007 (17)
December, 2006 (18)
November, 2006 (17)
October, 2006 (23)
September, 2006 (22)
August, 2006 (15)
July, 2006 (15)
June, 2006 (13)
May, 2006 (10)
April, 2006 (5)
March, 2006 (1)
February, 2006 (1)
January, 2006 (2)
December, 2005 (5)
November, 2005 (4)
October, 2005 (3)
September, 2005 (8)
August, 2005 (17)
July, 2005 (11)
June, 2005 (7)
May, 2005 (24)
April, 2005 (15)
March, 2005 (15)
February, 2005 (18)
January, 2005 (23)
December, 2004 (24)
November, 2004 (25)
October, 2004 (10)
September, 2004 (23)
August, 2004 (12)
July, 2004 (1)