<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gurock Software Blog &#187; Tobias Gurock</title>
	<atom:link href="http://blog.gurock.com/postings/author/tg/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.gurock.com</link>
	<description>Our products, programming &#38; business.</description>
	<lastBuildDate>Sat, 24 Dec 2011 14:19:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Aspect-oriented logging for .NET with PostSharp and SmartInspect</title>
		<link>http://blog.gurock.com/postings/aspect-oriented-logging-for-net-with-postsharp-and-smartinspect/848/</link>
		<comments>http://blog.gurock.com/postings/aspect-oriented-logging-for-net-with-postsharp-and-smartinspect/848/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 14:00:23 +0000</pubDate>
		<dc:creator>Tobias Gurock</dc:creator>
				<category><![CDATA[Gurock Software]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SmartInspect]]></category>
		<category><![CDATA[si-article]]></category>

		<guid isPermaLink="false">http://blog.gurock.com/?p=848</guid>
		<description><![CDATA[This article is part of a series about aspect-oriented logging with SmartInspect, our logging tool for .NET, Java and Delphi. Please see the first article of this series for a complete overview over the available posts. Our PostSharp aspect library has a new home: SmartInspect for PostSharp There are various AOP frameworks available for each [...]]]></description>
			<content:encoded><![CDATA[<p><em>This article is part of a series about aspect-oriented logging with <a href="http://www.gurock.com/smartinspect/">SmartInspect</a>, our logging tool for .NET, Java and Delphi. Please see the <a href="http://blog.gurock.com/postings/aspect-oriented-logging-and-smartinspect/814/">first article of this series</a> for a complete overview over the available posts.</em></p>
<p><strong>Our PostSharp aspect library has a new home: <a href="http://code.gurock.com/p/smartinspect-postsharp/">SmartInspect for PostSharp</a></strong></p>
<p>There are various AOP frameworks available for each of the three platforms SmartInspect supports, so why did we decide to start with <a href="http://www.postsharp.org/">PostSharp</a> for the first part of this blog series about apsect-oriented logging? PostSharp has become the de-facto standard AOP framework for .NET and there are many things to like about PostSharp:</p>
<ul>
<li>PostSharp is really easy to use. It integrates nicely with MSBuild (and therefore Visual Studio) and you just need to complete the PostSharp setup and are good to go.</li>
<li>It provides different APIs depending on what you are trying to accomplish. You can use a low-level API for injecting snippets of MSIL code for complexer tasks (PostSharp.Core) or a very simple high-level API (PostSharp.Laos) to develop aspects with custom .NET attributes.</li>
<li>It&#8217;s very well documented. The APIs are fully documented and there are getting started tutorials, videos, a plugin repository and lots more. Can&#8217;t get a lot better than that.</li>
<li>It&#8217;s a compile-time AOP framework. Unlike other tools which inject the AOP code at runtime, it post-processes the assemblies directly after compliation which is more efficient and allows for more flexibility.</li>
<li>Last but not least, some SmartInspect customers were already successfully using PostSharp in their applications and told us that they liked the combination of both tools (that&#8217;s how we became aware of PostSharp in the first place).</li>
</ul>
<p>We will be using the simpler Laos API for our SmartInspect PostSharp aspects, as we found it sufficient for all our needs. The resulting library is able to automatically trace method execution, log exceptions and watch changes of field variables. The library comes with three aspects for the different tasks, each implemented as a custom .NET attribute.</p>
<h2>Using the SmartInspect aspects</h2>
<p>The general procedure of using a PostSharp aspect is to install the <a href="http://www.postsharp.org/download">PostSharp framework</a> and to add the <code>PostSharp.Public</code> and <code>PostSharp.Laos</code> assembly references to your application. PostSharp injects itself into the MSBuild build process and automatically processes all assemblies that reference PostSharp.</p>
<p>For our logging aspects, you further need to add references to the <code>Gurock.SmartInspect</code> and <code>Gurock.SmartInspect.PostSharp</code> assemblies (the logging library and PostSharp aspects, respectively). The logging library is included in the <a href="http://www.gurock.com/smartinspect/trial/">SmartInspect trial download</a> and the SmartInspect AOP plugin can be downloaded from the <a href="http://www.gurock.com/smartinspect/resources/">SmartInspect resources page</a>.</p>
<h2>Tracing method execution</h2>
<p>The first aspect I am going to demonstrate is for tracing method execution. This aspect makes it really easy to generate a complete call trace of your application, showing you the entire application flow and letting you inspect stack traces at each execution point. It automatically generates two log messages for each method call: one for entering a method and one when a method exits. You can also log the passed method arguments (when entering a method) and the method result (when exiting a method), respectively.</p>
<p>To use this aspect, simple add the <code>SiTrace</code> custom attribute to your application as follows (note how you can continue to use SmartInspect for complementary log messages, of course):</p>
<p>[sourcecode language="csharp"]<br />
using System;<br />
using Gurock.SmartInspect;<br />
using Gurock.SmartInspect.PostSharp;</p>
<p>[assembly:SiTrace(SessionName=&quot;Main&quot;)]</p>
<p>namespace Gurock.SmartInspect.PostSharp.Samples<br />
{<br />
	class Program<br />
	{<br />
		static void Main(string[] args)<br />
		{<br />
			SiAuto.Si.Enabled = true; // Enable logging<br />
			Hello(&quot;World&quot;);<br />
			Goodbye(&quot;World&quot;);<br />
		}</p>
<p>		static void Hello(string name)<br />
		{<br />
			SiAuto.Main.LogMessage(&quot;Hello, {0}.&quot;, name);<br />
		}</p>
<p>		static string Goodbye(string name)<br />
		{<br />
			string msg = String.Format(&quot;Goodbye, {0}.&quot;, name);<br />
			SiAuto.Main.LogMessage(msg);<br />
			return msg;<br />
		}<br />
	}<br />
}<br />
[/sourcecode]</p>
<p>The attribute can be specified on a per-class/per-method basis or, like in our example, for the entire assembly. You can further specify filters for including/excluding certain modules/classes (called attribute targets in the PostSharp terminology), set aspect priorities (useful with nested aspects) <a href="http://www.postsharp.org/contributions/documentation">and much more</a>.</p>
<p>Our aspects have a few additional SmartInspect-related options. First, as you can see in the example above, you can set the session name used for sending log messages. If you do not want a hard-coded session name, you can tell the aspect to make use of the logging context and automatically adjust the name based on the current namespace or class. You can do so by setting a so called session policy. For example, to automatically use a session name that equals the name of the current class context, you can use a session policy of <code>SessionPolicy.TypeName</code> and omit the session name:</p>
<p>[sourcecode language="csharp"]<br />
&#8230;<br />
[assembly:SiTrace(SessionPolicy=SessionPolicy.TypeName)]<br />
&#8230;<br />
[/sourcecode]</p>
<p>There are additional options for including the method arguments (<code>IncludeArguments</code>) and method return value (<code>IncludeReturnValue</code>). With both options enabled, the resulting log looks as follows in the <a href="http://www.gurock.com/smartinspect/tour/1/">SmartInspect Console</a> (SmartInspect&#8217;s viewer application). Note how the automatic enter/exit messages are mixed with the manual log messages:</p>
<div class="framed-image">
<a href="/wp-content/uploads/2009/10/postsharp-sitrace.png"><img src="/wp-content/uploads/2009/10/postsharp-sitrace-small.png" alt="The SiTrace sample log shown in the SmartInspect Console" title="The SiTrace sample log shown in the SmartInspect Console" width="550" height="334" class="size-full wp-image-892" /></a><br />
<span>The SiTrace sample log shown in the <a href="http://www.gurock.com/smartinspect/tour/1/">SmartInspect Console</a></span>
</div>
<h2>Logging exceptions</h2>
<p>Another typical use-case for logging is recording all occurring exceptions and this is usually done by adding log calls to your exception handlers. Adding log statements to all your exception handlers can get tedious and error-prone though (e.g., you could forget to rethrow the exception after logging it), so we&#8217;ve added an aspect to automate this task for you. To use it, just add the <code>SiException</code> attribute to your code:</p>
<p>[sourcecode language="csharp"]<br />
using System;<br />
using Gurock.SmartInspect;<br />
using Gurock.SmartInspect.PostSharp;</p>
<p>&#8230;</p>
<p>[assembly: SiException(SessionName=&quot;Main&quot;)]</p>
<p>&#8230;</p>
<p>		static void Hello(string name)<br />
		{<br />
			SiAuto.Main.LogMessage(&quot;Hello, {0}.&quot;, name);<br />
			throw new Exception(&quot;This is a test exception&quot;);<br />
		}</p>
<p>&#8230;<br />
[/sourcecode]</p>
<p>Note how the exception is now automatically included in the resulting log (within the expected method context):</p>
<div class="framed-image">
<a href="/wp-content/uploads/2009/10/postsharp-siexception.png"><img src="/wp-content/uploads/2009/10/postsharp-siexception-small.png" alt="The SiException sample log shown in the SmartInspect Console" title="The SiException sample log shown in the SmartInspect Console" width="550" height="334" class="size-full wp-image-892" /></a><br />
<span>The SiException sample log shown in the <a href="http://www.gurock.com/smartinspect/tour/1/">SmartInspect Console</a></span>
</div>
<h2>Watching field values</h2>
<p>Arguably the most advanced aspect in this library is the <code>SiField</code> attribute. This attribute lets you automatically record any changes to values of object or class fields. The aspect gets notified whenever the value of a field changes and then logs the name of the field along with its old and new value. You can configure whether the aspect should send the name and values as normal log messages or as SmartInspect watches (for showing the latest values of a variable in the watches toolbox or for displaying its history as a chart in the watches graph). By default, both watches and normal messages are logged.</p>
<p>Let&#8217;s have a look at the following example which demonstrates <code>SiField</code> in practice. Note how we use <code>SiField</code> as an attribute for the entire assembly again. We could also limit it to individual classes or fields, either by writing the attribute above the classes/fields we want to inspect or by specifying filters/attribute targets for the global attribute.</p>
<p>[sourcecode language="csharp"]<br />
using System;<br />
using Gurock.SmartInspect;<br />
using Gurock.SmartInspect.PostSharp;</p>
<p>[assembly: SiField(SessionName = &quot;Main&quot;)]</p>
<p>namespace Gurock.SmartInspect.PostSharp.Samples<br />
{<br />
	class Program<br />
	{<br />
		public static int FIELD;</p>
<p>		static void Main(string[] args)<br />
		{<br />
			SiAuto.Si.Enabled = true; // Enable logging<br />
			Counting();<br />
		}</p>
<p>		static void Counting()<br />
		{<br />
			Random r = new Random();</p>
<p>			for (int i = 0; i &lt; 10; i++)<br />
			{<br />
				FIELD = r.Next(100);<br />
				Thread.Sleep(1000);<br />
			}<br />
		}<br />
	}<br />
}<br />
[/sourcecode]</p>
<p>And here&#8217;s the generated log in the SmartInspect Console:</p>
<div class="framed-image">
<a href="/wp-content/uploads/2009/10/postsharp-sifield.png"><img src="/wp-content/uploads/2009/10/postsharp-sifield-small.png" alt="The SiField sample log shown in the SmartInspect Console" title="The SiField sample log shown in the SmartInspect Console" width="550" height="334" class="size-full wp-image-892" /></a><br />
<span>The SiField sample log shown in the <a href="http://www.gurock.com/smartinspect/tour/1/">SmartInspect Console</a></span>
</div>
<p>As you can see, every field change is automatically logged and shown in the Console. The watches toolbox in the lower left of the Console displays the latest value of <code>FIELD</code> in addition to the normal log messages in the main view. Also note the watches graph on the right that displays the field&#8217;s history as a chart (with its values over time). I believe an upcoming version of PostSharp will also be able to watch properties and we will update our library accordingly when this feature is available.</p>
<p>The nice thing about these aspects is that they can be freely combined as you like. You can mix and match the aspects as needed. If you plan to use our aspects and library, I also recommend taking a look at the <a href="http://www.postsharp.org/">PostSharp documentation</a> for more details about aspects, AOP and PostSharp in general as well as how to configure PostSharp for more complex scenarios.</p>
<p>Feel free to <a href="mailto:tg@gurock.com">send me an email</a> or leave a comment on this blog in case you have any questions <a href="http://www.gurock.com/smartinspect/resources/">about this plugin</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gurock.com/postings/aspect-oriented-logging-for-net-with-postsharp-and-smartinspect/848/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Aspect-oriented logging and SmartInspect</title>
		<link>http://blog.gurock.com/postings/aspect-oriented-logging-and-smartinspect/814/</link>
		<comments>http://blog.gurock.com/postings/aspect-oriented-logging-and-smartinspect/814/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 08:00:04 +0000</pubDate>
		<dc:creator>Tobias Gurock</dc:creator>
				<category><![CDATA[Gurock Software]]></category>
		<category><![CDATA[SmartInspect]]></category>

		<guid isPermaLink="false">http://blog.gurock.com/?p=814</guid>
		<description><![CDATA[One of the things that bugs me a bit when adding logging code to applications is that they make the actual code harder to read. Each line of logging code competes with a real line of application code. You have to find a good trade-off between readability, logging performance and log coverage and that&#8217;s not [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things that bugs me a bit when adding logging code to applications is that they make the actual code harder to read. Each line of logging code competes with a real line of application code. You have to find a good trade-off between readability, logging performance and log coverage and that&#8217;s not easy to do in every case. Ideally, your entire application is well-instrumented and you can switch logging on or off for certain application modules depending on your needs. But this usually results in hundreds or thousands of additional lines of code, just for logging. Of course, the benefits from having all those log statements in place far outweighs the disadvantages of the code inflation, but still, those lines are anything but beautiful.</p>
<p>Another issue with logging is that adding all those log calls takes time and getting a good log coverage can get tedious when instrumenting a large existing application. That&#8217;s not necessarily the case if you add logging from the very beginning of development, but let&#8217;s face it, most applications have already reached a mature state before you think of adding diagnostics and logging features. Adding such features often comes as an afterthought (which it shouldn&#8217;t, ideally), so when you or a customer experience a problem which you cannot easily reproduce, you are instrumenting your application or parts of it and that isn&#8217;t any fun at all. We usually recommend instrumenting the most important parts of an application first and then building from there, but it&#8217;s still, well, time-consuming.</p>
<p>Fortunately, there are approaches and techniques to solve both of these problems, with one of the most promising being <em><a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming">aspect-oriented programming</a></em> (or AOP for short):</p>
<blockquote><p>&#8220;Aspect-oriented programming (AOP) is a programming paradigm that increases modularity by enabling improved separation of concerns. This entails breaking down a program into distinct parts (so-called concerns, cohesive areas of functionality). All programming paradigms support some level of grouping and encapsulation of concerns into separate, independent entities by providing abstractions (e.g. procedures, modules, classes, methods) that can be used to implement, abstract and compose these concerns. But some concerns defy these forms of implementation and are called crosscutting concerns because they &#8220;cut across&#8221; multiple abstractions in a program.&#8221;</p></blockquote>
<p>It&#8217;s been several years since I first heard about AOP. Back then, AOP was being marketed as one of the next big things in programming (okay, it&#8217;s been <em>several, several</em> years now). Supporters of AOP claimed it would change programming and software development as much as object-oriented programming did 20 years ago. We now know that it hasn&#8217;t and probably never will to that extend, but it&#8217;s for sure a nice addition to the developer&#8217;s toolbox.</p>
<p>So, what&#8217;s so special about AOP? The most beautiful aspect of AOP is that it improves the modularity of your application by putting parts that logically belong together in one central location. You can implement security concepts, caching, transactions, <a href="http://en.wikipedia.org/wiki/Design_by_contract">design by contract</a> and of course a complete logging solution without touching any of your existing classes or methods. This means there&#8217;s no need for repeated boiler plate code for checking method arguments for <code>null</code> values, no repetitions of the same begin/commit/rollback transaction code or for adding exception logging code to every exception handler. You simply tell the AOP framework which parts of your application should make use of which features (also called <em>aspects</em> in AOP terminology) and the AOP framework does all the work wiring those aspects to your application modules.</p>
<p>In the coming months, we will take a look at some of the available AOP frameworks for the different platforms supported by SmartInspect here on this blog and show how to build a sophisticated logging layer with these frameworks and our own <a href="http://www.gurock.com/smartinspect/">logging tool SmartInspect</a>. Stay tuned!</p>
<p>Articles published so far:</p>
<ul>
<li><a href="http://blog.gurock.com/postings/aspect-oriented-logging-for-net-with-postsharp-and-smartinspect/848/">Aspect-oriented logging for .NET with PostSharp and SmartInspect</a></li>
<li><a href="http://blog.gurock.com/postings/aspect-oriented-logging-for-net-with-unity-and-smartinspect/1386/">Aspect-oriented logging for .NET with Unity and SmartInspect</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.gurock.com/postings/aspect-oriented-logging-and-smartinspect/814/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Working with Delphi&#8217;s new Exception.StackTrace</title>
		<link>http://blog.gurock.com/postings/working-with-delphis-new-exception-stacktrace/730/</link>
		<comments>http://blog.gurock.com/postings/working-with-delphis-new-exception-stacktrace/730/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 16:30:16 +0000</pubDate>
		<dc:creator>Tobias Gurock</dc:creator>
				<category><![CDATA[DelphiFeeds.com]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SmartInspect]]></category>
		<category><![CDATA[si-article]]></category>

		<guid isPermaLink="false">http://blog.gurock.com/?p=730</guid>
		<description><![CDATA[One feature I often miss when using Delphi is the support for proper exception stack traces at run-time. You know, those useful stack traces that show you exactly where an exception occurred, ideally with the method name and line number of where the exception was raised. Both .NET and Java have excellent stack trace support [...]]]></description>
			<content:encoded><![CDATA[<p>One feature I often miss when using Delphi is the support for proper exception stack traces at run-time. You know, those useful stack traces that show you exactly where an exception occurred, ideally with the method name and line number of where the exception was raised. Both .NET and Java have excellent stack trace support built right into the framework and the Exception classes. You just call <a href="http://msdn.microsoft.com/en-us/library/system.exception.stacktrace.aspx">Exception.StackTrace</a> (.NET) or <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Throwable.html#getStackTrace%28%29">Exception.getStackTrace</a> (Java) and get a detailed analysis of where the exception was thrown and how it got passed to your exception handler.</p>
<p>Unfortunately, Delphi never had good (built-in) run-time support for stack traces. The features for stack traces during debugging in the IDE are/were okay, but there were nothing in the language or framework which helped you to find out programmatically where an exception occurred at run-time and, more importantly, how it got passed to your exception handler (besides the original exception address, maybe). So, I was happy to see that Delphi 2009 finally introduced a new StackTrace property which, I hoped, would return a full-blown stack trace when you caught an exception.</p>
<p>The initial happiness soon wore off when I realized that the StackTrace property was really just a placeholder to <em>return a stack trace from a possible stack trace provider</em> rather than a real stack trace implementation. So, without such a provider (and there&#8217;s none that comes directly with Delphi), there is still no way to get a stack trace for your exceptions. Though a bit disappointing, the good thing is that there&#8217;s now finally a standardized way to get a stack trace, even if it&#8217;s not implemented by default.</p>
<p>Exception reporting tools such as <a href="http://www.eurekalog.com/">Eurekalog</a> or <a href="http://www.madshi.net/madExceptDescription.htm">madExcept</a> or debug helpers such as the <a href="http://sourceforge.net/projects/jcl/">JclDebug</a> unit can register themselves as providers and use their engines to return a stack trace when an exception is raised. I&#8217;ve built a small unit which demonstrates this with the Jcl in combination with our logging tool <a href="http://www.gurock.com/smartinspect/">SmartInspect</a> and I&#8217;ve heard Fabio of Eurekalog is working on a similar feature for his component:</p>
<p>[sourcecode language='delphi']<br />
unit StackTrace;</p>
<p>interface</p>
<p>uses<br />
  SysUtils, Classes, JclDebug;</p>
<p>implementation</p>
<p>function GetExceptionStackInfoProc(P: PExceptionRecord): Pointer;<br />
var<br />
  LLines: TStringList;<br />
  LText: String;<br />
  LResult: PChar;<br />
begin<br />
  LLines := TStringList.Create;<br />
  try<br />
    JclLastExceptStackListToStrings(LLines, True, True, True, True);<br />
    LText := LLines.Text;<br />
    LResult := StrAlloc(Length(LText));<br />
    StrCopy(LResult, PChar(LText));<br />
    Result := LResult;<br />
  finally<br />
    LLines.Free;<br />
  end;<br />
end;</p>
<p>function GetStackInfoStringProc(Info: Pointer): string;<br />
begin<br />
  Result := string(PChar(Info));<br />
end;</p>
<p>procedure CleanUpStackInfoProc(Info: Pointer);<br />
begin<br />
  StrDispose(PChar(Info));<br />
end;</p>
<p>initialization<br />
  // Start the Jcl exception tracking and register our Exception<br />
  // stack trace provider.<br />
  if JclStartExceptionTracking then<br />
  begin<br />
    Exception.GetExceptionStackInfoProc := GetExceptionStackInfoProc;<br />
    Exception.GetStackInfoStringProc := GetStackInfoStringProc;<br />
    Exception.CleanUpStackInfoProc := CleanUpStackInfoProc;<br />
  end;</p>
<p>finalization<br />
  // Stop Jcl exception tracking and unregister our provider.<br />
  if JclExceptionTrackingActive then<br />
  begin<br />
    Exception.GetExceptionStackInfoProc := nil;<br />
    Exception.GetStackInfoStringProc := nil;<br />
    Exception.CleanUpStackInfoProc := nil;<br />
    JclStopExceptionTracking;<br />
  end;<br />
end.<br />
[/sourcecode]</p>
<p>The unit merely starts and stops the exception tracking of the Jcl, implements a minimal stack trace provider and registers for the Exception provider events. The GetExceptionStackInfoProc and CleanUpStackInfoProc functions are automatically called by the RTL to give the provider the opportunity to initialize and cleanup the stack trace after an exception occurred. GetStackInfoStringProc is called indirectly when you access the StackTrace property and is responsible for returning the actual stack trace. </p>
<p>So, how do you use this unit? Let&#8217;s have a look at the following example:</p>
<p>[sourcecode language='delphi']<br />
&#8230;</p>
<p>uses<br />
  &#8230;, StackTrace;</p>
<p>type<br />
  TForm1 = class(TForm)<br />
    Button1: TButton;<br />
    procedure Button1Click(Sender: TObject);<br />
  private<br />
    procedure SomeMethod;<br />
  end;</p>
<p>implementation</p>
<p>procedure TForm1.Button1Click(Sender: TObject);<br />
begin<br />
  try<br />
    SomeMethod;<br />
  except<br />
    // Log the exception: We use SmartInspect here because it has<br />
    // built-in support for Exception.StackTrace but you could also<br />
    // access the StackTrace property here directly.<br />
    SiMain.LogException;<br />
  end;<br />
end;</p>
<p>procedure TForm1.SomeMethod;<br />
begin<br />
  raise Exception.Create(&#8216;A test exception&#8217;);<br />
end;</p>
<p>&#8230;<br />
[/sourcecode]</p>
<p>As you can see, using this unit is just a matter of adding it to our uses clause. It won&#8217;t get any simpler than that. The unit will take care of registering/unregistering itself as a stack trace provider and when you now access the StackTrace property of an Exception object, you will get a detailed stack trace. To include the method names and line numbers in the stack trace, make sure to let the linker include debug symbols into your application and to enable the &#8216;Use debug .dcus&#8217; option in case you also want line numbers from the VCL and RTL methods.</p>
<div style="text-align: center">
<a href="/wp-content/uploads/2009/10/delphi-stacktrace.png"><br />
<img src="/wp-content/uploads/2009/10/delphi-stacktrace-small.png" alt="delphi-stacktrace-small" title="delphi-stacktrace-small" width="550" height="441" class="aligncenter size-full wp-image-787" /></a><br />
<em>The <a href="http://www.gurock.com/smartinspect/">SmartInspect Console</a> showing the stack trace of an exception</em>
</div>
<p>Now, when you use SmartInspect for logging and have a stack trace provider registered, all your logged exceptions automatically include the exception&#8217;s call stack. Pretty useful, isn&#8217;t it?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gurock.com/postings/working-with-delphis-new-exception-stacktrace/730/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>SmartInspect 3.2: new build available</title>
		<link>http://blog.gurock.com/postings/smartinspect-32-new-build-available/514/</link>
		<comments>http://blog.gurock.com/postings/smartinspect-32-new-build-available/514/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 12:15:39 +0000</pubDate>
		<dc:creator>Tobias Gurock</dc:creator>
				<category><![CDATA[DelphiFeeds.com]]></category>
		<category><![CDATA[Gurock Software]]></category>
		<category><![CDATA[SmartInspect]]></category>

		<guid isPermaLink="false">http://blog.gurock.com/?p=514</guid>
		<description><![CDATA[I&#8217;ve just uploaded a new build of SmartInspect 3.2. The new build contains an important fix for a problem where the SmartInspect Console may become unresponsive/locked for a few seconds (while loading a log file or scrolling a view, for example). The exact version number of the new build is 3.2.0.8546. If you&#8217;ve already downloaded [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just uploaded a new build of SmartInspect 3.2. The new build contains an important fix for a problem where the SmartInspect Console may become unresponsive/locked for a few seconds (while loading a log file or scrolling a view, for example). The exact version number of the new build is 3.2.0.8546. If you&#8217;ve already downloaded and installed the 3.2 earlier this week, please download and install the updated version. You can install the new version over your existing installation.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gurock.com/postings/smartinspect-32-new-build-available/514/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Delphi 2009 and backwards compatibility</title>
		<link>http://blog.gurock.com/postings/delphi-2009-and-backwards-compatibility/471/</link>
		<comments>http://blog.gurock.com/postings/delphi-2009-and-backwards-compatibility/471/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 17:57:51 +0000</pubDate>
		<dc:creator>Tobias Gurock</dc:creator>
				<category><![CDATA[DelphiFeeds.com]]></category>
		<category><![CDATA[SmartInspect]]></category>

		<guid isPermaLink="false">http://blog.gurock.com/?p=471</guid>
		<description><![CDATA[In a recent blog post I saw on DelphiFeeds.com, Babnik argues that Delphi 2009 should have been compatible with older Delphi versions by still treating String as an AnsiString and introducing a parallel VCL with UnicodeStrings (think TEdit vs. TEditW). I don&#8217;t think this would have been a good idea. I understand that there are [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent blog post I saw on <a href="http://www.delphifeeds.com/">DelphiFeeds.com</a>, <a href="http://thedorictemple.blogspot.com/2009/03/breaking-existing-code.html">Babnik argues</a> that Delphi 2009 should have been compatible with older Delphi versions by still treating String as an AnsiString and introducing a parallel VCL with UnicodeStrings (think TEdit vs. TEditW). I don&#8217;t think this would have been a good idea.</p>
<p>I understand that there are many Delphi users who want to upgrade to Delphi 2009 to benefit from additional features but don&#8217;t care about the Unicode improvements (or already use a different technique to support Unicode such as the TNT Controls). Adding this compatibility mode would therefore be a great short-term solution for them but would result <a href="http://martinfowler.com/bliki/TechnicalDebt.html">in huge technical debt</a> for CodeGear.</p>
<p>For CodeGear, this would mean supporting two parallel versions of the VCL for at least the next few versions of Delphi. What a support and maintenance nightmare! Likewise, third-party vendors would have to ship two different versions of their products for Delphi 2009 and beyond. One compiled with Unicode support and one without. Again, a maintenance nightmare.</p>
<p>I admit that porting real-world applications to Delphi 2009 can be quite a bit of work. The <a href="http://blog.gurock.com/?p=460">just released version of SmartInspect</a> now uses Delphi 2009 for the SmartInspect Console. Previous versions were built against Delphi 2006 and I can say that the transition wasn&#8217;t as smooth as I hoped for. Like Babniks product, the SmartInspect Console already supported Unicode by using WideStrings and the TNT Controls, so there wasn&#8217;t a need to update to Delphi 2009 just because of Unicode. But we wanted to fix a few Vista related bugs and other glitches and Delphi 2009 includes fixes for most of them. So we decided to give Delphi 2009 a try.</p>
<p>It turned out that converting the Console itself wasn&#8217;t that big of a problem. The warning messages of the Delphi 2009 compiler are really helpful and we got most of the Console running within about two weeks. A bit more problematic were some no longer maintained third-party controls and it took two more weeks to get the Console to a really stable state. That&#8217;s more than I expected but still okay for such a one-time conversion (the Console has about 50K LoC + forms, the unmaintained third-party controls were about 10K I guess).</p>
<p>In retrospect, I think it was well-worth the time and Delphi 2009 feels like a good version. The IDE is much more stable than Delphi 2006 and the language and VCL finally got some much-needed improvements. We are also happy that we could throw away the WideString and TNT related code. Using Delphi 2009 makes the Console code much cleaner. It also got a bit faster because of the performance improvements of UnicodeString compared to WideString.</p>
<p>So, while I can understand that not everyone wants to invest the time for the Delphi 2009 conversion, I do not think that adding this compatibility mode would have been a good decision, especially not in the long run.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gurock.com/postings/delphi-2009-and-backwards-compatibility/471/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>SmartInspect 3.2 is available</title>
		<link>http://blog.gurock.com/postings/smartinspect-32-is-available/460/</link>
		<comments>http://blog.gurock.com/postings/smartinspect-32-is-available/460/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 13:14:22 +0000</pubDate>
		<dc:creator>Tobias Gurock</dc:creator>
				<category><![CDATA[DelphiFeeds.com]]></category>
		<category><![CDATA[Gurock Software]]></category>
		<category><![CDATA[SmartInspect]]></category>

		<guid isPermaLink="false">http://blog.gurock.com/?p=460</guid>
		<description><![CDATA[We are happy to announce the release of SmartInspect 3.2. Besides adding some often requested features to the Console and logging libraries, we made some major changes to the SmartInspect Console in how it loads and processes log files, reducing the memory usage during log file loading drastically and making it faster in general. We&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>We are happy to announce the release of SmartInspect 3.2. Besides adding some often requested features to the Console and logging libraries, we made some major changes to the SmartInspect Console in how it loads and processes log files, reducing the memory usage during log file loading drastically and making it faster in general.</p>
<p>We&#8217;ve also upgraded the Console to make use of the latest development tools and third-party components available, integrating it better with Windows Vista and preparing it for Windows 7.</p>
<p>If you have been using the beta versions, you won&#8217;t notice a lot of changes  as we have only added a few additional bug fixes since the last beta. Here are the main changes of SmartInspect 3.2 compared to the previous stable release:</p>
<ul>
<li>New: Connection variables for automatically replacing variables in a connection string</li>
<li>New: Width format option for text protocol pattern string</li>
<li>New: Custom timestamp format for text protocol pattern string (platform-specific)</li>
<li>New: Exception.StackTrace support for LogException (Delphi only)</li>
<li>New: Support for protocol objects in addition to raw streams in the Dispatch method of the memory protocol</li>
<li>New: ‘View | Create View’ Console feature for quickly opening new filtered views</li>
<li>New: Console command line parameter /configdir and /pipename</li>
<li>New: Internal string pooling which drastically reduces the overall memory consumption of the Console
<li>Improved: Log file loading performance increased and reduced memory consumption</li>
<li>Improved: Bookmarks in the Console now indicate whether they are already in use</li>
<li>Improved: Better view performance when displaying large Log Entry titles</li>
<li>Improved: Increased performance of title and data viewers</li>
</ul>
<p>This is also the first release that includes the memory consumption improvements we implemented in the Console and explained on our <a href="http://nobugleftbehind.com">software quality blog</a>. You can download the release from <a href="http://my.gurock.com/">My Gurock.com</a> and the updated trial is available <a href="http://www.gurock.com/downloads/">on our website</a>. As usual, you can simply install the new version over your existing installation. For a complete list of changes, please see the online help or our <a href="http://www.gurock.com/support/forum/forum-3.html">announcement forum</a>.</p>
<p>SmartInspect 3.2 is a great release and contains quite a few new features and lots of smaller improvements and fixes. You can expect a few blog postings about some of the new features to appear here soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gurock.com/postings/smartinspect-32-is-available/460/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New SmartInspect beta versions</title>
		<link>http://blog.gurock.com/postings/new-smartinspect-beta-versions/441/</link>
		<comments>http://blog.gurock.com/postings/new-smartinspect-beta-versions/441/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 12:03:20 +0000</pubDate>
		<dc:creator>Tobias Gurock</dc:creator>
				<category><![CDATA[DelphiFeeds.com]]></category>
		<category><![CDATA[Gurock Software]]></category>
		<category><![CDATA[SmartInspect]]></category>

		<guid isPermaLink="false">http://blog.gurock.com/?p=441</guid>
		<description><![CDATA[We&#8217;ve just uploaded a new beta build for the upcoming SmartInspect 3.2.0 release. The exact version number is 3.2.0.8496. This build integrates several additional techniques to reduce the memory consumption of the SmartInspect Console, the most important being a new string pool for caching and reusing strings. You can read more about this string pool [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve just uploaded a new beta build for the upcoming <a href="http://www.gurock.com/products/smartinspect/">SmartInspect</a> 3.2.0 release. The exact version number is 3.2.0.8496. This build integrates several additional techniques to reduce the memory consumption of the SmartInspect Console, the most important being a new string pool for caching and reusing strings. You can read more about this string pool on our new <a href="http://nobugleftbehind.com/optimizing-memory-consumption-with-string-pools-part-i/">software quality blog</a>. As usual, the new build can be downloaded via <a href="http://my.gurock.com/">My Gurock.com</a>. You can report bugs in our <a href="http://www.gurock.com/support/forum/forum-2.html">SmartInspect EAP forum</a>.</p>
<p>We also updated the SmartInspect for PHP library. It contains a few bug fixes and can be downloaded from our <a href="http://www.gurock.com/products/smartinspect/resources/">SmartInspect resource page</a>. Please see the smartinspect.php file for changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gurock.com/postings/new-smartinspect-beta-versions/441/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New SmartInspect EAP Versions (and the SmartInspect Router)</title>
		<link>http://blog.gurock.com/postings/new-smartinspect-eap-versions-and-the-smartinspect-router/316/</link>
		<comments>http://blog.gurock.com/postings/new-smartinspect-eap-versions-and-the-smartinspect-router/316/#comments</comments>
		<pubDate>Sat, 14 Jun 2008 12:48:54 +0000</pubDate>
		<dc:creator>Tobias Gurock</dc:creator>
				<category><![CDATA[DelphiFeeds.com]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Gurock Software]]></category>
		<category><![CDATA[SmartInspect]]></category>

		<guid isPermaLink="false">http://blog.gurock.com/?p=316</guid>
		<description><![CDATA[We&#8217;ve released two new EAP versions in the last few days. On Thursday, we released the 3.0.2 EAP which fixes a few problems in the Console/Configuration Builder (most of the Console bugs were related to the shutdown behavior and pipe server). And a few minutes ago, I uploaded the new 3.0.3 version which introduces a [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve released two new EAP versions in the last few days. On Thursday, we released the 3.0.2 EAP which fixes a few problems in the Console/Configuration Builder (most of the Console bugs were related to the shutdown behavior and pipe server). And a few minutes ago, I uploaded the new 3.0.3 version which introduces a new SmartInspect service application called the SmartInspect Router. From the docs:</p>
<blockquote><p>The SmartInspect Router is a Windows service application which can receive SmartInspect log packets via TCP/IP or named pipes and routes them to different log destinations. The supported log destinations are the same as those from the SmartInspect libraries, namely log files, TCP/IP or named pipes. Two typical uses of the SmartInspect Router are to combine multiple client logs into a single log file and to collect logs in a central location. The SmartInspect Router is intended to provide a common logging infrastructure for distributed systems, multi-process applications and web applications.</p></blockquote>
<p>Since SmartInspect is used more and more for web applications and distributed systems it became clear that we needed a server application that can receive logs via TCP/IP or named pipes and stores them in a central location. Many customers have expressed their need for such a solution. </p>
<p>We began work on the SmartInspect Router a few months ago and are happy to finally release the first version in this EAP. After installing the new EAP version, you can find the setup of the SmartInspect Router in the deploy directory of your SmartInspect EAP installation. The SmartInspect Router can be configured with a simple XML configuration file (please see the included help for details).</p>
<p>Releasing a completely new application is always a challenge and there might be a few things that don&#8217;t work correctly. If you encounter a problem with the SmartInspect Router, we would appreciate a comment in our <a href="http://www.gurock.com/support/forum/forum-2.html">SmartInspect EAP forum</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gurock.com/postings/new-smartinspect-eap-versions-and-the-smartinspect-router/316/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SmartInspect Early Access Program</title>
		<link>http://blog.gurock.com/postings/smartinspect-early-access-program/301/</link>
		<comments>http://blog.gurock.com/postings/smartinspect-early-access-program/301/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 17:48:42 +0000</pubDate>
		<dc:creator>Tobias Gurock</dc:creator>
				<category><![CDATA[DelphiFeeds.com]]></category>
		<category><![CDATA[Gurock Software]]></category>
		<category><![CDATA[SmartInspect]]></category>

		<guid isPermaLink="false">http://blog.gurock.com/?p=301</guid>
		<description><![CDATA[Every now and then we get questions about beta versions or technology previews of upcoming SmartInspect releases. So far, we have been hesitant to release beta versions. But in order to become a bit more transparent in what we are working on for SmartInspect, we decided to start a SmartInspect Early Access Program (EAP). In [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright alignnone size-full wp-image-304" style="float: right; border: 0; margin-left: 10px;" title="SmartInspect EAP" src="http://blog.gurock.com/wp-content/uploads/2008/04/smartinspectlogo-eap2.png" alt="SmartInspect EAP" width="206" height="68" /></p>
<p>Every now and then we get questions about beta versions or technology previews of upcoming <a href="http://www.gurock.com/products/smartinspect/">SmartInspect</a> releases. So far, we have been hesitant to release beta versions. But in order to become a bit more transparent in what we are working on for SmartInspect, we decided to start a SmartInspect Early Access Program (EAP). In this EAP, we will provide interested customers with technology previews and beta versions of SmartInspect. We plan to release new EAP versions on a frequent basis.</p>
<p>To download EAP versions of SmartInspect, you need to have a customer account on our <a href="http://my.gurock.com/">My Gurock.com</a> customer portal and an active SmartInpect support plan. After logging in to My Gurock.com, you should notice a new menu item called “EAP” with the latest EAP releases. Note that EAP versions might include incomplete or buggy features and/or might not work as expected. They haven&#8217;t gone through the entire QA cycle yet and are only provided for testing purposes. These versions are not intended to be used on production systems and are therefore not fully supported.</p>
<h2>What&#8217;s new in this EAP version?</h2>
<p>The first version of the EAP is a preview version of the upcoming SmartInspect 3.0 major release. Please note that this EAP release is not a feature-complete preview version of SmartInspect 3.0. It contains most major features of the upcoming major version but lacks several smaller features which will be added over the next few weeks. We will post more about the 3.0 version soon. Here is a short list of new major features that are already available in the first EAP release:</p>
<ul>
<li><strong>New named pipe protocol:</strong> The new named pipe protocol is the new default protocol instead of TCP/IP and provides a great performance increase for local live logging. Also, since it&#8217;s very fast to test if a pipe is available, automatically reconnecting is really useful for production systems now. This means that you can start the Console when your application is already running and you will immediately receive live logging packets.</li>
<li><strong>Improved SmartInspect sessions:</strong> It is now possible to specify log levels on a per-session basis. Sessions can now also be configured via SmartInspect configuration files. This is really great for production systems like ASP.NET applications, as you can now enable or disable logging for specific users directly via config files.</li>
<li><strong>Support for log file encryption:</strong> SmartInspect now supports log file encryption. You can specify an encryption key for log files in the SmartInspect libraries and the logging data is automatically encrypted with AES. This feature can be useful if you log sensitive information that has to be protected.</li>
<li><strong>Asynchronous logging:</strong> You can now specify for each logging connection if you want to log asynchronously. The libraries will create a (configurable) buffer and process logging data in a separate thread. This feature is very useful for high-performance production systems or for logging via TCP/IP with regular reconnects.</li>
<li><strong>Configuration timer:</strong> The new configuration timer allows you to automatically reload SmartInspect configuration files when the config has changed. This allows applications to pick up logging configuration changes without the need to be restarted.</li>
<li><strong>Sorting of packets:</strong> An often requested feature is the ability to merge log files based on the timestamps of the log packets. The SmartInspect Console now supports this with its new Sort feature.</li>
<li><strong>Improved Console navigation:</strong> We also added new navigation features to the Console like Go to Time, Synchronize and back-/forward actions.</li>
</ul>
<p>There are other new features that are not mentioned in the list above. Please refer to the What&#8217;s New section of the online help for a complete list of new things.</p>
<h2>Installing EAP and official versions side-by-side</h2>
<p>It is generally possible to install EAP and official releases on the same machine, but please be aware of the following issues:</p>
<ul>
<li>You should install EAP releases into a directory different from your official SmartInspect installation. Doing otherwise overrides your existing installation.</li>
<li>Do not activate the IDE library integration in the EAP setup if you plan to further use the official versions of the libraries. Doing otherwise can override your existing integration.</li>
<li>After installing an EAP release, double-clicking log files in the Windows Explorer opens them with the new EAP versions of the Console (same for config files and the Configuration Builder).</li>
</ul>
<p>To avoid the possibility of interfering with an existing installation altogether, it is highly recommended to install EAP releases on virtual machines only. Please note that you can reuse your existing SmartInspect 2.x license key for this EAP version.</p>
<h2>Will SmartInspect 3.0 be free for existing customers?</h2>
<p>If you have an active support plan when SmartInspect 3.0 is released, you can download and use the new SmartInspect version without paying any upgrade fees. And because every SmartInspect license already includes one free support plan year, you will get the 3.0 for free if you purchased SmartInspect recently (or if you plan to purchase new licenses now). If your support plan expired, you can renew your support plan by logging in to <a href="http://my.gurock.com/">My Gurock.com</a>.</p>
<h2>Providing feedback</h2>
<p>If you are experiencing problems with this (or a future) EAP version or if you have suggestions or feature requests, please post them it in the related <a href="http://www.gurock.com/support/forum/forum-2.html">forum</a> or <a href="http://www.gurock.com/support/email/">email us</a>. We would really love to hear your feedback!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gurock.com/postings/smartinspect-early-access-program/301/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SmartInspect for Delphi 5 (yes, Delphi 5!)</title>
		<link>http://blog.gurock.com/postings/smartinspect-for-delphi-5-yes-delphi-5/274/</link>
		<comments>http://blog.gurock.com/postings/smartinspect-for-delphi-5-yes-delphi-5/274/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 20:51:51 +0000</pubDate>
		<dc:creator>Tobias Gurock</dc:creator>
				<category><![CDATA[DelphiFeeds.com]]></category>
		<category><![CDATA[Gurock Software]]></category>
		<category><![CDATA[SmartInspect]]></category>

		<guid isPermaLink="false">http://blog.gurock.com/postings/smartinspect-for-delphi-5-yes-delphi-5/274/</guid>
		<description><![CDATA[From time to time we get questions about using SmartInspect in combination with Delphi 5. There seem to be surprisingly many people who still use this particular version of Delphi. Delphi 5 was a nice release back then and it seems like a lot of people simply don&#8217;t feel the need to upgrade to a [...]]]></description>
			<content:encoded><![CDATA[<p>From time to time we get questions about using <a href="http://www.gurock.com/products/smartinspect/">SmartInspect</a> in combination with Delphi 5. There seem to be surprisingly many people who still use this particular version of Delphi. Delphi 5 was a nice release back then and it seems like a lot of people simply don&#8217;t feel the need to upgrade to a newer version or still use it for legacy applications.</p>
<p>Although we don&#8217;t officially support Delphi 5 with SmartInspect 2.x, we had a version of the SmartInspect Delphi library for SmartInspect 1.4 which runs fine with Delphi 5. This library doesn&#8217;t support some of <a href="http://www.gurock.com/products/smartinspect/whatsnew/2.0/">the newer features of SmartInspect 2.x</a> like Unicode (this is actually the main reason we don&#8217;t support Delphi 5 with SmartInspect 2.x because Delphi 5 lacks a lot of Unicode related functions), the Watches Graph, the backlog protocol feature and others. The good news is that the current Console version is fully backwards-compatible and can work with the data from older SmartInspect libraries. You thus still benefit from some of the new features like the marker functionality or the improved filtering and navigation capabilities even when using the old library.</p>
<p>So, if you need a logging solution for your Delphi 5 application, <a href="http://www.gurock.com/about/contact/">send us an email</a> and we are happy to help you evaluate SmartInspect with Delphi 5.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gurock.com/postings/smartinspect-for-delphi-5-yes-delphi-5/274/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

