<?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>Scott Elkin &#187; Exceptions</title> <atom:link href="http://scottelkin.com/category/programming/exceptions/feed/" rel="self" type="application/rss+xml" /><link>http://scottelkin.com</link> <description>Tech, Love, Life</description> <lastBuildDate>Thu, 07 Apr 2011 23:02:52 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Add Additional Information to Your Exceptions</title><link>http://scottelkin.com/programming/aspnet-20/add-additional-information-to-your-exceptions/</link> <comments>http://scottelkin.com/programming/aspnet-20/add-additional-information-to-your-exceptions/#comments</comments> <pubDate>Wed, 19 Jul 2006 07:37:00 +0000</pubDate> <dc:creator>Scott</dc:creator> <category><![CDATA[ASP.NET 2.0]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[Enterprise Library]]></category> <category><![CDATA[Exceptions]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">/archive/2006/07/19/Add-Additional-Information-to-Your-Exceptions.aspx</guid> <description><![CDATA[When Enterprise Library was called Microsoft Application Blocks, if you wanted to log an Exception, you would write (assuming &#8220;ex&#8221; is an Exception): ExceptionManager.Publish(ex) And if you wanted to log some extended properties you could do something like this: NameValueCollection customerInfo = new NameValueCollection(); customerInfo.Add("name","scott"); customerInfo.Add("email","blah@blah.com"); ExceptionManager.Publish(ex,customerInfo); Now that I am upgrading all legacy code [...]No related posts.]]></description> <content:encoded><![CDATA[<p>When Enterprise Library was called Microsoft Application Blocks, if you wanted to log an Exception, you would write (assuming &#8220;ex&#8221; is an Exception):</p><pre><code>ExceptionManager.Publish(ex)</code></pre><p>And if you wanted to log some extended properties you could do something like this:</p><pre><code>NameValueCollection customerInfo = new NameValueCollection();
customerInfo.Add("name","scott");
customerInfo.Add("email","blah@blah.com");
ExceptionManager.Publish(ex,customerInfo);
</code></pre><p>Now that I am upgrading all legacy code to Enterprise Library 2006 for .NET 2.0, I couldn’t find a way to do this since the only way to log an error is:</p><pre><code>ExceptionPolicy.HandleException(ex, "General Policy");
</code></pre><p>where “General Policy” is the name of the Exception Policy in the config file telling the Block what to do with the exception.</p><p>Looking in the config file, I noticed a formatter template with the following at the tail end of the template attribute, “…Extended Properties: {dictionary({key} &#8211; {value} )}&#8221;.  The formatter template is used to format the exception that is about to be logged somewhere.  Looking through the code for where it loops through this Dictionary, I noticed it accessing an IDictionary of <a href="http://msdn2.microsoft.com/en-us/library/system.exception.data.aspx">Exception.Data</a>.  Exception.Data?  Where did that come from?</p><p>Data is a new .NET framework 2.0 property of the Exception class to allow you to add any user-defined information about the exception.  Nothing more to it:  Just a simple name/value dictionary for your enjoyment.  As if you couldn’t figure it out, my new code would look like:</p><pre><code>ex.Data.Add("name","scott");
ex.Data.Add("email","blah@blah.com");
ExceptionPolicy.HandleException(ex, "General Policy");</code></pre><p>And as long as you use the default formatter, it will log this data at the end of the FormattedException field.</p><p>No related posts.</p>]]></content:encoded> <wfw:commentRss>http://scottelkin.com/programming/aspnet-20/add-additional-information-to-your-exceptions/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)

Served from: scottelkin.com @ 2012-05-17 23:58:50 -->
