CRM 4.0 (or SharePoint or custom application) and DebugView


Every now and then I’m find myself trying to solve same issues over and over again 🙂 That’s why I found myself (again) using DebugView as my debugging assistant at remote box. If you don’t know what DebugView is then you should definitely try it out. I’m going to give you few ideas how you could use it at your applications. You can download the DebugView from Technet.

Why do I use DebugView? Well I want to get debug messages from running system BUT… I don’t want to write to EventLog or to File since it’s totally unnecessary to write all the messages all the time. I just want messages when I’m ready to observe the system. And DebugView is handy tool for that. Here is list of steps how I normally implement that kind of approach:
1) Create log class that implements logging/tracing/debugging (this is pretty much just wrapper to few simple method calls) (I recommend making this as singleton)
2) Use you log class in your application/solution
3) Use DebugView to follow the trace messages written by your log class

In 1) I mention that I recommend using singleton approach at the log class. This is important especially at the CRM 4.0 where you need to add default trace listener so that you’ll get the trace messages. Here is the code example for that:

1
2
3
using System.Diagnostics;
// ...
Trace.Listeners.Add(new DefaultTraceListener());

After you have added the default listener you can just use this oneliner:

1
Trace.WriteLine("My Trace: " + message);

Now your trace can be seen at the DebugView:
DebugView
(here is CRM 4.0 where I have menu item that points to custom ASPX page and I’m using “My Trace” to see what’s happening in there)

DebugView has many built-in functionalities like “Save As” etc. that can help you on your debug/trace efforts. So I recommend that you learn to play around with it.

I also had the magic word “SharePoint” in my title. That is for the simple reason that this same story applies to SharePoint too. And don’t forget… Since System.Diagnostics.Trace is implemented at the .NET Framework this story also applies to all other applications which are built on top of that.

You might also want to read my previous post about tracing: CRM 4.0, SharePoint and ASP.NET Trace.

Anyways… Happy hacking!

J

Comments (3)

  1. AndersR says:

    Same goes for System.Diagnostics.Debug.WriteLine(msg,category) which comes in handy when you want to filter your messages in DebugView using the category as filter.

  2. Ludger says:

    does that also work for you when you are writing plugins for ms crm?

    I cannot get the debug view working for plugin messages in my MS CRM 4.0 installation. Are there any tricks I missed?

Skip to main content