I recently had the opportunity to check out a software package that does logging for several platforms, .NET, Delphi and Java. The software is called SmartInspect and it’s by Gurock Software (www.gurock.com). SmartInspect adds a very flexible methodology to do logging in your software. Being a full time .NET programmer, I examined their API for logging in this platform only.
.NET has built in tracing and logging so why do you need another package? Because they do all the hard work of making the .NET logging useful! They provide an easy way to log all .NET types and more importantly, get the logged data back in a useful way to make intelligent decisions based on it. More on that later.
Another cool feature that they offer is the output of logs to either a file or a tcp client. This allowed me to direct the output of the log when running in debug mode directly to their log viewer. No fooling with log files in development! Every run of the program is right in front of me.You could also direct live clients to a tcp server to do large collections of data if you needed to.
So how do we log something? Is it easy? No, it’s very easy. The learning curve is small and the API is intuitive.I was almost fully up to speed in about two hours. Even if you haven’t used a particular method before, the names make sense. For example, to log the start of a method you use:
The end of a method?
There are many different logging methods for the native .NET types. SmartInspect’s done all the hard work of parsing the type you pass to them and extracting meaningful information to show you later. They range from simple types to much more complex types like a DataSet.
bool MyBool = true;
DataSet MyDataSet = new DataSet();
OK so that’s all nice, but now what do I do with all this information? One of the major downsides to logs are that they usually have thousands of entries that are plain text. It’s up to you to figure out how and what do to with all the megabytes of text. SmartInspect solves this problem very well. The real power of the tool is in their log viewer.
It’s very customizable and presents the log information in a well laid out manner. Below is a screen shot of a few things I logged in a button click.
You can see the button1_click entry point and exit, along with a Boolean, DataSet and exception that I logged. Each type of log entry has an associated viewer that allows you to see the information for the entry. Below is the DataSet (a single table, with 2 columns ID and Name) that I logged. Notice that it shows the two records that were in it.
SmartInspect Page 2
Since this was a short log it’s easy to find what we want. In a large log, you need a way to filter what you’re seeing to find specific entries. SmartInspect provides several ways to filter data. You have several built in filters and you can also build your own.
They are simple to apply. Just select one and you have your entire log filtered. For instance, I can separate an ASP.Net log by each user’s session.
You can also build your own filters using a simple to use dialog.
There are many other features such as bookmarks, comments, the ability to search for methods and separators. It’s easy to be searching through a log and have to stop and do something else or need to pass information on to another developer. SmartInspect lets me add my notes to it easily. Just right click. You can see I added a comment below.
Overall I was very impressed with SmartInspect. It’s easy to use with almost no learning curve and the logs are presented in a useful way instead of lines of useless text. I’ve only scraped the surface of the log viewer here and its capabilities. I highly suggest you download a demo copy and play with it yourself.
I am also going to include a macro that I wrote.In order to help facilitate adding the EnterMethod and LeaveMethod to each function I write, I designed a macro. Just put your cursor in your C# method and run the macro. It will put the enter and leave tags in your code and read the method name for them. It’s not tested extensively so use at your own risk . It’s provided as is.
Dim projectItem As ProjectItem = DTE.ActiveDocument.ProjectItem
Dim fileCodeModel As FileCodeModel = projectItem.FileCodeModel
' Get the current selection
Dim selection As TextSelection = DTE.ActiveDocument.Selection
' Get the current cursor location
Dim point As TextPoint = selection.ActivePoint
' Try to read the current location as a code element
Dim codeElement As CodeElement = _
If (codeElement Is Nothing) Then
MsgBox("Place mouse cursor in a method before running this macro.", _
Dim codeFunction As CodeFunction = CType(codeElement, CodeFunction)
Dim fieldName As String = codeFunction.Name
Dim startPoint As EditPoint = codeFunction.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint
startPoint.Insert("SiAuto.Main.EnterMethod(""" & fieldName & """);")
Dim endPoint As EditPoint = codeFunction.GetEndPoint(vsCMPart.vsCMPartBody).CreateEditPoint
endPoint.Insert("SiAuto.Main.LeaveMethod(""" & fieldName & """);")