<?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>hamang.net &#187; ASP.NET</title>
	<atom:link href="http://hamang.net/tag/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://hamang.net</link>
	<description>- the everyday life</description>
	<lastBuildDate>Tue, 15 Feb 2011 10:05:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Extend the GridView</title>
		<link>http://hamang.net/2009/02/19/extend-the-gridview/</link>
		<comments>http://hamang.net/2009/02/19/extend-the-gridview/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 10:29:56 +0000</pubDate>
		<dc:creator>Knut Hamang</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://hamang.net/2009/02/19/extend-the-gridview/</guid>
		<description><![CDATA[The default GridView class has by default a lot of great features. However, some important features are missing. One of the most important is the ability to display the grid even if it is empty. Here is a great class extending the GridView with some additional features. http://forums.asp.net/p/1012442/2951765.aspx#2951765]]></description>
			<content:encoded><![CDATA[<p>The default GridView class has by default a lot of great features. However, some important features are missing. One of the most important is the ability to display the grid even if it is empty.<br />
Here is a great class extending the GridView with some additional features.</p>
<p><a href="http://forums.asp.net/p/1012442/2951765.aspx#2951765" target="_blank">http://forums.asp.net/p/1012442/2951765.aspx#2951765</a></p>
]]></content:encoded>
			<wfw:commentRss>http://hamang.net/2009/02/19/extend-the-gridview/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Web application absolute path</title>
		<link>http://hamang.net/2008/12/17/web-application-absolute-path/</link>
		<comments>http://hamang.net/2008/12/17/web-application-absolute-path/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 13:56:37 +0000</pubDate>
		<dc:creator>Knut Hamang</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://hamang.net/?p=176</guid>
		<description><![CDATA[Just a reminder on how to get the absolute path for the webapplication in ASP.NET HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) +        VirtualPathUtility.ToAbsolute(HttpContext.Current.Request.ApplicationPath) This will return http://subdomain.domain.com/applicationname You can drop those AppSettings with ApplicationPath]]></description>
			<content:encoded><![CDATA[<p>Just a reminder on how to get the absolute path for the webapplication in ASP.NET</p>
<p>HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) +        VirtualPathUtility.ToAbsolute(HttpContext.Current.Request.ApplicationPath)</p>
<p>This will return http://subdomain.domain.com/applicationname</p>
<p>You can drop those AppSettings with ApplicationPath <img src='http://hamang.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://hamang.net/2008/12/17/web-application-absolute-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using log4net in Web Applications &#8211; a real-life example</title>
		<link>http://hamang.net/2008/12/12/using-log4net-in-web-applications-a-reallife-example/</link>
		<comments>http://hamang.net/2008/12/12/using-log4net-in-web-applications-a-reallife-example/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 08:30:08 +0000</pubDate>
		<dc:creator>Knut Hamang</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://hamang.net/?p=164</guid>
		<description><![CDATA[I have seen many different configurations for Log4Net. Log4Net is a very simple, but flexible framework and there are lot of ways to configure it. Here is a real-life example on how we are using in the applications I am working on. First off, I won&#039;t say that this is the one and only way [...]]]></description>
			<content:encoded><![CDATA[<p>I have seen many different configurations for Log4Net. Log4Net is a very simple, but flexible framework and there are lot of ways to configure it. Here is a real-life example on how we are using in the applications I am working on.</p>
<p>First off, I won&#039;t say that this is the one and only way you should use Log4Net, but it handles most of the scenarios I can think of.  Some people think that one should not write wrappers for the loggers and use the logging framework directly in the class, but to be honest I like the wrapper because it makes it very simple to use the logging framework without too much knowledge on how it works. I would say that 95% of what is being logged, is typically errors and debug/useful information. I can&#039;t see any problem using a wrapper as I get the information I need from the loggers.</p>
<h3>Goals with this log configuration</h3>
<ul>
<li>Most important is of course logging errors. All errors should be logged.</li>
<li>Errors should be logged in a global file on the server that will role once a day.</li>
<li>Errors should be sent by email.</li>
<li>It should be possible to notify important information by email</li>
<li>It should be easy for the developers to use the logging framework</li>
<li>It should be possible to change log-level without restarting the application</li>
</ul>
<h3>Configuration and setup</h3>
<p>Log4Net consists of only one DLL. Get the latest version and put it in your bin folder. Make a reference to it in the Web Application Project.</p>
<h3>Log4net.config</h3>
<p>Create a new config file in the root of your Web Application. Name it Log4Net.config and paste the following code:</p>
<p><!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;\red0\green128\blue0;}??\fs20 \cf1 &lt;?\cf3 xml\cf1  \cf4 version\cf1 =\cf0 "\cf1 1.0\cf0 "\cf1  \cf4 encoding\cf1 =\cf0 "\cf1 utf-8\cf0 "\cf1  ?&gt;\par ??&lt;\cf3 configuration\cf1 &gt;\par ??    &lt;\cf3 configSections\cf1 &gt;\par ??        &lt;\cf3 section\cf1  \cf4 name\cf1 =\cf0 "\cf1 log4net\cf0 "\cf1  \cf4 type\cf1 =\cf0 "\cf1 log4net.Config.Log4NetConfigurationSectionHandler, log4net\cf0 "\cf1  /&gt;\par ??    &lt;/\cf3 configSections\cf1 &gt;\par ??    &lt;\cf3 log4net\cf1 &gt;\par ??        &lt;\cf3 appender\cf1  \cf4 name\cf1 =\cf0 "\cf1 RollingLogFileAppender\cf0 "\cf1  \cf4 type\cf1 =\cf0 "\cf1 log4net.Appender.RollingFileAppender\cf0 "\cf1 &gt;\par ??            &lt;\cf3 threshold\cf1  \cf4 value\cf1 =\cf0 "\cf1 INFO\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 file\cf1  \cf4 value\cf1 =\cf0 "\cf1 Log\\[applicationname].log\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 appendToFile\cf1  \cf4 value\cf1 =\cf0 "\cf1 true\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 rollingStyle\cf1  \cf4 value\cf1 =\cf0 "\cf1 Date\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 datePattern\cf1  \cf4 value\cf1 =\cf0 "\cf1 '.'yyyyMMdd'.log'\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 layout\cf1  \cf4 type\cf1 =\cf0 "\cf1 log4net.Layout.PatternLayout\cf0 "\cf1 &gt;\par ??                &lt;\cf3 conversionPattern\cf1  \cf4 value\cf1 =\cf0 "\cf1 %date [%thread] %-5level %logger %X\{user\} %X\{url\} - %message%newline\cf0 "\cf1  /&gt;\par ??            &lt;/\cf3 layout\cf1 &gt;\par ??        &lt;/\cf3 appender\cf1 &gt;\par ??        &lt;\cf3 appender\cf1  \cf4 name\cf1 =\cf0 "\cf1 SmtpAppenderError\cf0 "\cf1  \cf4 type\cf1 =\cf0 "\cf1 log4net.Appender.SmtpAppender\cf0 "\cf1 &gt;\par ??            &lt;! \cf6 Set threshold for this appender\cf1  &gt;\par ??            &lt;\cf3 threshold\cf1  \cf4 value\cf1 =\cf0 "\cf1 WARN\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 to\cf1  \cf4 value\cf1 =\cf0 "\cf1 [someone]@[somewhere.com]\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 from\cf1  \cf4 value\cf1 =\cf0 "\cf1 [someone]@[somewhere.com]\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 subject\cf1  \cf4 value\cf1 =\cf0 "\cf1 Error from [applicationname]\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 smtpHost\cf1  \cf4 value\cf1 =\cf0 "\cf1 [100.100.100.100]\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 bufferSize\cf1  \cf4 value\cf1 =\cf0 "\cf1 1\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 lossy\cf1  \cf4 value\cf1 =\cf0 "\cf1 false\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 layout\cf1  \cf4 type\cf1 =\cf0 "\cf1 log4net.Layout.PatternLayout\cf0 "\cf1 &gt;\par ??                &lt;\cf3 conversionPattern\cf1  \cf4 value\cf1 =\cf0 "\cf1 %date %-5level %logger %X\{user\} %X\{url\} - %message%newline\cf0 "\cf1  /&gt;\par ??            &lt;/\cf3 layout\cf1 &gt;\par ??        &lt;/\cf3 appender\cf1 &gt;\par ??        &lt;\cf3 appender\cf1  \cf4 name\cf1 =\cf0 "\cf1 SmtpAppenderNotify\cf0 "\cf1  \cf4 type\cf1 =\cf0 "\cf1 log4net.Appender.SmtpAppender\cf0 "\cf1 &gt;\par ??            &lt;! \cf6 Set threshold for this appender\cf1  &gt;\par ??            &lt;\cf3 threshold\cf1  \cf4 value\cf1 =\cf0 "\cf1 INFO\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 to\cf1  \cf4 value\cf1 =\cf0 "\cf1 [someone]@[somewhere.com]\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 from\cf1  \cf4 value\cf1 =\cf0 "\cf1 [someone]@[somewhere.com]\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 subject\cf1  \cf4 value\cf1 =\cf0 "\cf1 Error from [applicationname]\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 smtpHost\cf1  \cf4 value\cf1 =\cf0 "\cf1 [100.100.100.100]\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 bufferSize\cf1  \cf4 value\cf1 =\cf0 "\cf1 1\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 lossy\cf1  \cf4 value\cf1 =\cf0 "\cf1 false\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 layout\cf1  \cf4 type\cf1 =\cf0 "\cf1 log4net.Layout.PatternLayout\cf0 "\cf1 &gt;\par ??                &lt;\cf3 conversionPattern\cf1  \cf4 value\cf1 =\cf0 "\cf1 %date - %message%newline\cf0 "\cf1  /&gt;\par ??            &lt;/\cf3 layout\cf1 &gt;\par ??        &lt;/\cf3 appender\cf1 &gt;\par ??        &lt;\cf3 root\cf1 &gt;\par ??            &lt;\cf3 level\cf1  \cf4 value\cf1 =\cf0 "\cf1 Error\cf0 "\cf1  /&gt;        \par ??        &lt;/\cf3 root\cf1 &gt;\par ??        &lt;\cf3 logger\cf1  \cf4 name\cf1 =\cf0 "\cf1 Application\cf0 "\cf1 &gt;\par ??            &lt;! \cf6 Set level for this logger\cf1  &gt;\par ??            &lt;\cf3 level\cf1  \cf4 value\cf1 =\cf0 "\cf1 INFO\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 appender-ref\cf1  \cf4 ref\cf1 =\cf0 "\cf1 RollingLogFileAppender\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 appender-ref\cf1  \cf4 ref\cf1 =\cf0 "\cf1 SmtpAppenderError\cf0 "\cf1  /&gt;\par ??        &lt;/\cf3 logger\cf1 &gt;\par ??        &lt;\cf3 logger\cf1  \cf4 name\cf1 =\cf0 "\cf1 Notify\cf0 "\cf1 &gt;\par ??            &lt;! \cf6 Set level for this logger\cf1  &gt;\par ??            &lt;\cf3 level\cf1  \cf4 value\cf1 =\cf0 "\cf1 INFO\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 appender-ref\cf1  \cf4 ref\cf1 =\cf0 "\cf1 RollingLogFileAppender\cf0 "\cf1  /&gt;\par ??            &lt;\cf3 appender-ref\cf1  \cf4 ref\cf1 =\cf0 "\cf1 SmtpAppenderNotify\cf0 "\cf1  /&gt;\par ??        &lt;/\cf3 logger\cf1 &gt;\par ??    &lt;/\cf3 log4net\cf1 &gt;\par ??&lt;/\cf3 configuration\cf1 &gt;} --></p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black;">
<pre style="margin: 0px;"><span style="color: blue;">&lt;?</span><span style="color: #a31515;">xml</span><span style="color: blue;"> </span><span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">1.0</span>"<span style="color: blue;"> </span><span style="color: red;">encoding</span><span style="color: blue;">=</span>"<span style="color: blue;">utf-8</span>"<span style="color: blue;"> ?&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">configuration</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">    &lt;</span><span style="color: #a31515;">configSections</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;</span><span style="color: #a31515;">section</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">log4net</span>"<span style="color: blue;"> </span><span style="color: red;">
        type</span><span style="color: blue;">=</span>"<span style="color: blue;">log4net.Config.Log4NetConfigurationSectionHandler, log4net</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">    &lt;/</span><span style="color: #a31515;">configSections</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">    &lt;</span><span style="color: #a31515;">log4net</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;</span><span style="color: #a31515;">appender</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">RollingLogFileAppender</span>"<span style="color: blue;">
            </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">log4net.Appender.RollingFileAppender</span>"<span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">threshold</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">INFO</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">file</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Log\[applicationname].log</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">appendToFile</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">true</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">rollingStyle</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Date</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">datePattern</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">'.'yyyyMMdd'.log'</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">layout</span><span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">log4net.Layout.PatternLayout</span>"<span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">                &lt;</span><span style="color: #a31515;">conversionPattern</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">%date [%thread] %-5level
                  %logger %X{user} %X{url} - %message%newline</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;/</span><span style="color: #a31515;">layout</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;/</span><span style="color: #a31515;">appender</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;</span><span style="color: #a31515;">appender</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">SmtpAppenderError</span>"<span style="color: blue;"> </span><span style="color: red;">
                  type</span><span style="color: blue;">=</span>"<span style="color: blue;">log4net.Appender.SmtpAppender</span>"<span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;!--</span><span style="color: green;">Set threshold for this appender</span><span style="color: blue;">--&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">threshold</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">ERROR</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">to</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">[someone]@[somewhere.com]</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">from</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">[someone]@[somewhere.com]</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">subject</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Error from [applicationname]</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">smtpHost</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">[100.100.100.100]</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">bufferSize</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">1</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">lossy</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">false</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">layout</span><span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">log4net.Layout.PatternLayout</span>"<span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">                &lt;</span><span style="color: #a31515;">conversionPattern</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">%date %-5level
                %logger %X{user} %X{url} - %message%newline</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;/</span><span style="color: #a31515;">layout</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;/</span><span style="color: #a31515;">appender</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;</span><span style="color: #a31515;">appender</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">SmtpAppenderNotify</span>"<span style="color: blue;">
                  </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">log4net.Appender.SmtpAppender</span>"<span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;!--</span><span style="color: green;">Set threshold for this appender</span><span style="color: blue;">--&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">threshold</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">INFO</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">to</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">[someone]@[somewhere.com]</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">from</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">[someone]@[somewhere.com]</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">subject</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Error from [applicationname]</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">smtpHost</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">[100.100.100.100]</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">bufferSize</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">1</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">lossy</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">false</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">layout</span><span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">log4net.Layout.PatternLayout</span>"<span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">                &lt;</span><span style="color: #a31515;">conversionPattern</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">%date - %message%newline</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;/</span><span style="color: #a31515;">layout</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;/</span><span style="color: #a31515;">appender</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;</span><span style="color: #a31515;">root</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">level</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Error</span>"<span style="color: blue;"> /&gt;        </span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;/</span><span style="color: #a31515;">root</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;</span><span style="color: #a31515;">logger</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Application</span>"<span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;!--</span><span style="color: green;">Set level for this logger</span><span style="color: blue;">--&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">level</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">INFO</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">appender-ref</span><span style="color: blue;"> </span><span style="color: red;">ref</span><span style="color: blue;">=</span>"<span style="color: blue;">RollingLogFileAppender</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">appender-ref</span><span style="color: blue;"> </span><span style="color: red;">ref</span><span style="color: blue;">=</span>"<span style="color: blue;">SmtpAppenderError</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;/</span><span style="color: #a31515;">logger</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;</span><span style="color: #a31515;">logger</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Notify</span>"<span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;!--</span><span style="color: green;">Set level for this logger</span><span style="color: blue;">--&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">level</span><span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">INFO</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">appender-ref</span><span style="color: blue;"> </span><span style="color: red;">ref</span><span style="color: blue;">=</span>"<span style="color: blue;">RollingLogFileAppender</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">            &lt;</span><span style="color: #a31515;">appender-ref</span><span style="color: blue;"> </span><span style="color: red;">ref</span><span style="color: blue;">=</span>"<span style="color: blue;">SmtpAppenderNotify</span>"<span style="color: blue;"> /&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">        &lt;/</span><span style="color: #a31515;">logger</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">    &lt;/</span><span style="color: #a31515;">log4net</span><span style="color: blue;">&gt;</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">&lt;/</span><span style="color: #a31515;">configuration</span><span style="color: blue;">&gt;
</span></pre>
</div>
<p>Some comments on the Log4net.config file:</p>
<ul>
<li>The RollingFileAppender is great for rolling the logfile once a day.
<ul>
<li>It has a threshold of INFO, meaning it will log anything from the application except debug information</li>
<li>The logfiles are created in a subdirectory of web root. This should be changed on the production server to not expose information about the application.</li>
<li>The datePattern is specifying how the rolling files are named. The current day will be named &#034;applicationname.log&#034; and yesterdays file will be named &#034;applicationname.log.20081211.log&#034;. The rolling file extension (.log)  makes it easy to open the file in the same editor as the current log. All files will be sorted correctly when using the ISO style date in the filename.</li>
<li>In the conversionPattern you will see two speacial entries with the following format: %X{name}. These are custom formats which can be used for special purposes. This configuration adds the authenticated username and the url which fails if there is an error. This is useful information.</li>
</ul>
</li>
<li>The SmtpAppenders are used for sending emails. It&#039;s really not my favourite configuration, spamming the developers or some other people with emails when some errors occur, but some like it.
<ul>
<li>The threshold is different for the two SmtpAppenders, as is the subject of the email.</li>
<li>The buffersize is set to 1 in the example, meaning that the email is sent right away when an error occur. Increasing the buffer will hold the email until the buffer is reached. This can be useful on the production server, especially for the Notify appender as it is probably not that important to notify right away.</li>
<li>Lossy is set to false, also to send the email right away. It is possible to hold the email until an evaluator is triggered, for instance when a error occurs. Setting lossy to true requires an evaluator.</li>
<li>It is possible to add filters to the appenders to determine which emails should be sent and which to drop.</li>
</ul>
</li>
<li>There are two specific loggers that the application will use. The root logger can be used to log 3.party libraries also using Log4Net. I like to use specific loggers in the application and enabling the root logger if I am tracing an error where I need more information from 3.party libraries, ie. NHibernate or other frameworks using Log4net. Remember to set the level for the logger. If not set, the default level is WARN, which means INFO messages will not be logged.</li>
</ul>
<p>To be able to use the Log4Net.config file instead of putting everything into web.config, you will need to add the following line to AssemblyInfo.vb:</p>
<p><!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red163\green21\blue21;\red0\green0\blue255;}??\fs20 &lt;Assembly: log4net.Config.XmlConfigurator(ConfigFile:=\cf3 "Log4Net.config"\cf0 , Watch:=\cf4 True\cf0 )&gt; } --></p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<pre style="margin: 0px;">&lt;Assembly: log4net.Config.XmlConfigurator(ConfigFile:=<span style="color: #a31515;">"Log4Net.config"</span>, Watch:=<span style="color: blue;">True</span>)&gt;</pre>
</div>
<p>The advantage of separating the Log4Net configuration is that it is possible to change the configuration of the logging without restarting the application by changing web.config.  It also gives an better overview of the configuration, not having to browse through web.config to find the logging configuration.</p>
<h3>Logging unhandled errors</h3>
<p>All unhandled errors should be logged, which is pretty easy to achieve in web applications. Here is the Global.asax file:</p>
<p><!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red0\green128\blue0;\red163\green21\blue21;}??\fs20 \cf1 Imports\cf0  System.Web\par ??\cf1 Imports\cf0  log4net\par ??\cf1 Imports\cf0  MainLib\par ??\par ??\cf1 Public\cf0  \cf1 Class\cf0  [Global]\par ??    \cf1 Inherits\cf0  System.Web.HttpApplication\par ??\par ??    \cf1 Sub\cf0  Application_Start(\cf1 ByVal\cf0  sender \cf1 As\cf0  \cf1 Object\cf0 , \cf1 ByVal\cf0  e \cf1 As\cf0  EventArgs)\par ??        \cf4 ' Fires when the application is started\par ??\cf0         \cf4 ' Initialize the logger in this context.\par ??\cf0         LogManager.GetLogger(\cf1 Me\cf0 .GetType)\par ??        LogHandler.LogInfo(\cf5 "============================"\cf0 , LogHandler.LogType.General)\par ??        LogHandler.LogInfo(\cf5 "    Starting application"\cf0 , LogHandler.LogType.General)\par ??        LogHandler.LogInfo(\cf5 "============================"\cf0 , LogHandler.LogType.General)\par ??    \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Sub\cf0  Session_Start(\cf1 ByVal\cf0  sender \cf1 As\cf0  \cf1 Object\cf0 , \cf1 ByVal\cf0  e \cf1 As\cf0  EventArgs)\par ??        \cf4 ' Fires when the session is started\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Sub\cf0  Application_BeginRequest(\cf1 ByVal\cf0  sender \cf1 As\cf0  \cf1 Object\cf0 , \cf1 ByVal\cf0  e \cf1 As\cf0  EventArgs)\par ??        \cf4 ' Fires at the beginning of each request\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Sub\cf0  Application_AuthenticateRequest(\cf1 ByVal\cf0  sender \cf1 As\cf0  \cf1 Object\cf0 , \cf1 ByVal\cf0  e \cf1 As\cf0  EventArgs)\par ??        \cf4 ' Fires upon attempting to authenticate the use\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Sub\cf0  Application_Error(\cf1 ByVal\cf0  sender \cf1 As\cf0  \cf1 Object\cf0 , \cf1 ByVal\cf0  e \cf1 As\cf0  EventArgs)\par ??        \cf4 ' Fires when an error occurs\par ??\cf0         LogHandler.LogError(\cf5 "Unhandled exception occured!"\cf0 , HttpContext.Current.User, HttpContext.Current.User, HttpContext.Current.Server.GetLastError())\par ??    \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Sub\cf0  Session_End(\cf1 ByVal\cf0  sender \cf1 As\cf0  \cf1 Object\cf0 , \cf1 ByVal\cf0  e \cf1 As\cf0  EventArgs)\par ??        \cf4 ' Fires when the session ends\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Sub\cf0  Application_End(\cf1 ByVal\cf0  sender \cf1 As\cf0  \cf1 Object\cf0 , \cf1 ByVal\cf0  e \cf1 As\cf0  EventArgs)\par ??        \cf4 ' Fires when the application ends\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??End\cf0  \cf1 Class\par ??} --></p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<pre style="margin: 0px;"><span style="color: blue;">Imports</span> System.Web</pre>
<pre style="margin: 0px;"><span style="color: blue;">Imports</span> log4net</pre>
<pre style="margin: 0px;"><span style="color: blue;">Imports</span> MainLib</pre>
<pre style="margin: 0px;"><span style="color: blue;">Public</span> <span style="color: blue;">Class</span> [Global]</pre>
<pre style="margin: 0px;">    <span style="color: blue;">Inherits</span> System.Web.HttpApplication</pre>
<pre style="margin: 0px;">    <span style="color: blue;">Sub</span> Application_Start(<span style="color: blue;">ByVal</span> sender <span style="color: blue;">As</span> <span style="color: blue;">Object</span>, <span style="color: blue;">ByVal</span> e <span style="color: blue;">As</span> EventArgs)</pre>
<pre style="margin: 0px;">        <span style="color: green;">' Fires when the application is started</span></pre>
<pre style="margin: 0px;">        <span style="color: green;">' Initialize the logger in this context.</span></pre>
<pre style="margin: 0px;">        LogManager.GetLogger(<span style="color: blue;">Me</span>.GetType)</pre>
<pre style="margin: 0px;">        LogHandler.LogInfo(<span style="color: #a31515;">"============================"</span>, LogHandler.LogType.General)</pre>
<pre style="margin: 0px;">        LogHandler.LogInfo(<span style="color: #a31515;">"    Starting application"</span>, LogHandler.LogType.General)</pre>
<pre style="margin: 0px;">        LogHandler.LogInfo(<span style="color: #a31515;">"============================"</span>, LogHandler.LogType.General)</pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Sub</span> Session_Start(<span style="color: blue;">ByVal</span> sender <span style="color: blue;">As</span> <span style="color: blue;">Object</span>, <span style="color: blue;">ByVal</span> e <span style="color: blue;">As</span> EventArgs)</pre>
<pre style="margin: 0px;">        <span style="color: green;">' Fires when the session is started</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Sub</span> Application_BeginRequest(<span style="color: blue;">ByVal</span> sender <span style="color: blue;">As</span> <span style="color: blue;">Object</span>, <span style="color: blue;">ByVal</span> e <span style="color: blue;">As</span> EventArgs)</pre>
<pre style="margin: 0px;">        <span style="color: green;">' Fires at the beginning of each request</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Sub</span> Application_AuthenticateRequest(<span style="color: blue;">ByVal</span> sender <span style="color: blue;">As</span> <span style="color: blue;">Object</span>, <span style="color: blue;">ByVal</span> e <span style="color: blue;">As</span> EventArgs)</pre>
<pre style="margin: 0px;">        <span style="color: green;">' Fires upon attempting to authenticate the use</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Sub</span> Application_Error(<span style="color: blue;">ByVal</span> sender <span style="color: blue;">As</span> <span style="color: blue;">Object</span>, <span style="color: blue;">ByVal</span> e <span style="color: blue;">As</span> EventArgs)</pre>
<pre style="margin: 0px;">        <span style="color: green;">' Fires when an error occurs</span></pre>
<pre style="margin: 0px;">        LogHandler.LogError(<span style="color: #a31515;">"Unhandled exception occured!"</span>,
        HttpContext.Current.User, HttpContext.Current.Request.Url,
        HttpContext.Current.Server.GetLastError())</pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Sub</span> Session_End(<span style="color: blue;">ByVal</span> sender <span style="color: blue;">As</span> <span style="color: blue;">Object</span>, <span style="color: blue;">ByVal</span> e <span style="color: blue;">As</span> EventArgs)</pre>
<pre style="margin: 0px;">        <span style="color: green;">' Fires when the session ends</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Sub</span> Application_End(<span style="color: blue;">ByVal</span> sender <span style="color: blue;">As</span> <span style="color: blue;">Object</span>, <span style="color: blue;">ByVal</span> e <span style="color: blue;">As</span> EventArgs)</pre>
<pre style="margin: 0px;">        <span style="color: green;">' Fires when the application ends</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Class</span></pre>
</div>
<p>Comments on Global.asax</p>
<ul>
<li>I have added some information logging in the Application_Start event. This will trigger every time the applications starts or recycles. If this occurs often you probably have some problems with resources on the server, ie. too little memory available for the application.</li>
<li>Application_Error occurs every time an unhandled error occurs. Use this to log all errors not logged elsewhere.</li>
<li>I have to initialize the logging framework in Application_Start by calling
<p style="margin: 0px;">LogManager.GetLogger(<span style="color: blue;">Me</span>.GetType).  I&#039;m not sure whether this is a bug or by design. It is not possible to let the LogHandler do the initialization. LogHandler is a wrapper class located in another assembly, maybe that is a problem, without really knowing why. LogManager is a class in Log4Net.</p>
</li>
</ul>
<h3>The LogHandler class</h3>
<p><!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red163\green21\blue21;\red0\green128\blue0;}??\fs20 \cf1 Imports\cf0  System.Security.Principal\par ??\cf1 Imports\cf0  log4net\par ??\par ??\par ??\cf1 Public\cf0  \cf1 Class\cf0  LogHandler\par ??    \cf1 Const\cf0  _defaultApplicationLogger \cf1 As\cf0  \cf1 String\cf0  = \cf4 "Application"\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Enum\cf0  LogType\par ??        General\par ??        Notify\par ??    \cf1 End\cf0  \cf1 Enum\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Shared\cf0  \cf1 Sub\cf0  LogError(\cf1 ByVal\cf0  message \cf1 As\cf0  \cf1 String\cf0 , \cf1 ByVal\cf0  user \cf1 As\cf0  IPrincipal, \cf1 ByVal\cf0  url \cf1 As\cf0  Uri, \cf1 ByVal\cf0  [error] \cf1 As\cf0  Exception)\par ??        \cf1 Dim\cf0  logger \cf1 As\cf0  ILog = LogManager.GetLogger(_defaultApplicationLogger)\par ??        \cf1 If\cf0  \cf1 Not\cf0  [error].InnerException \cf1 Is\cf0  \cf1 Nothing\cf0  \cf1 Then\par ??\cf0             [error] = [error].InnerException\par ??        \cf1 End\cf0  \cf1 If\par ??\par ??\cf0         \cf5 'set user to log4net context, so we can use %X\{user\} in the appenders\par ??\cf0         \cf1 If\cf0  \cf1 Not\cf0  user \cf1 Is\cf0  \cf1 Nothing\cf0  \cf1 AndAlso\cf0  user.Identity.IsAuthenticated \cf1 Then\par ??\cf0             MDC.[Set](\cf4 "user"\cf0 , user.Identity.Name)\par ??        \cf1 End\cf0  \cf1 If\par ??\par ??\cf0         \cf5 'set url to log4net context, so we can use %X\{url\} in the appenders\par ??\cf0         MDC.[Set](\cf4 "url"\cf0 , url.ToString())\par ??\par ??        \cf1 If\cf0  logger.IsErrorEnabled \cf1 Then\par ??\cf0             logger.Error(message, [error])\par ??        \cf1 End\cf0  \cf1 If\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Shared\cf0  \cf1 Sub\cf0  LogInfo(\cf1 ByVal\cf0  message \cf1 As\cf0  \cf1 String\cf0 , \cf1 ByVal\cf0  type \cf1 As\cf0  LogType)\par ??        \cf1 Dim\cf0  logger \cf1 As\cf0  ILog = \cf1 Nothing\par ??\cf0         \cf1 If\cf0  type = LogType.Notify \cf1 Then\par ??\cf0             logger = LogManager.GetLogger(LogType.Notify.ToString)\par ??        \cf1 Else\par ??\cf0             logger = LogManager.GetLogger(_defaultApplicationLogger)\par ??        \cf1 End\cf0  \cf1 If\par ??\par ??\cf0         \cf1 If\cf0  logger.IsInfoEnabled \cf1 Then\par ??\cf0             logger.Info(message)\par ??        \cf1 End\cf0  \cf1 If\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??End\cf0  \cf1 Class\par ??} --></p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red163\green21\blue21;\red0\green128\blue0;}??\fs20 \cf1 Imports\cf0  System.Security.Principal\par ??\cf1 Imports\cf0  log4net\par ??\par ??\cf1 Public\cf0  \cf1 Class\cf0  LogHandler\par ??    \cf1 Const\cf0  _defaultApplicationLogger \cf1 As\cf0  \cf1 String\cf0  = \cf4 "Application"\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Enum\cf0  LogType\par ??        General\par ??        Notify\par ??    \cf1 End\cf0  \cf1 Enum\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Shared\cf0  \cf1 Sub\cf0  LogError(\cf1 ByVal\cf0  message \cf1 As\cf0  \cf1 String\cf0 , \cf1 ByVal\cf0  [error] \cf1 As\cf0  Exception)\par ??\par ??        \cf1 Dim\cf0  logger \cf1 As\cf0  ILog = LogManager.GetLogger(_defaultApplicationLogger)\par ??        \cf1 If\cf0  \cf1 Not\cf0  [error].InnerException \cf1 Is\cf0  \cf1 Nothing\cf0  \cf1 Then\par ??\cf0             [error] = [error].InnerException\par ??        \cf1 End\cf0  \cf1 If\par ??\par ??\cf0         \cf1 If\cf0  logger.IsErrorEnabled \cf1 Then\par ??\cf0             logger.Error(message, [error])\par ??        \cf1 End\cf0  \cf1 If\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Shared\cf0  \cf1 Sub\cf0  LogError(\cf1 ByVal\cf0  message \cf1 As\cf0  \cf1 String\cf0 , _\par ??                                \cf1 ByVal\cf0  user \cf1 As\cf0  IPrincipal, \cf1 ByVal\cf0  url \cf1 As\cf0  Uri, _\par ??                                \cf1 ByVal\cf0  [error] \cf1 As\cf0  Exception)\par ??        SetOptionalParametersOnLogger(user, url)\par ??        LogError(message, [error])\par ??    \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Shared\cf0  \cf1 Sub\cf0  LogInfo(\cf1 ByVal\cf0  message \cf1 As\cf0  \cf1 String\cf0 , \cf1 ByVal\cf0  type \cf1 As\cf0  LogType)\par ??        \cf1 Dim\cf0  logger \cf1 As\cf0  ILog = \cf1 Nothing\par ??\cf0         \cf1 If\cf0  type = LogType.Notify \cf1 Then\par ??\cf0             logger = LogManager.GetLogger(LogType.Notify.ToString)\par ??        \cf1 Else\par ??\cf0             logger = LogManager.GetLogger(_defaultApplicationLogger)\par ??        \cf1 End\cf0  \cf1 If\par ??\cf0         \cf1 If\cf0  logger.IsInfoEnabled \cf1 Then\par ??\cf0             logger.Info(message)\par ??        \cf1 End\cf0  \cf1 If\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Shared\cf0  \cf1 Sub\cf0  LogWarning(\cf1 ByVal\cf0  message \cf1 As\cf0  \cf1 String\cf0 , \cf1 ByVal\cf0  [error] \cf1 As\cf0  Exception)\par ??        \cf1 Dim\cf0  logger \cf1 As\cf0  ILog = LogManager.GetLogger(_defaultApplicationLogger)\par ??        \cf1 If\cf0  \cf1 Not\cf0  [error].InnerException \cf1 Is\cf0  \cf1 Nothing\cf0  \cf1 Then\par ??\cf0             [error] = [error].InnerException\par ??        \cf1 End\cf0  \cf1 If\par ??\cf0         \cf1 If\cf0  logger.IsWarnEnabled \cf1 Then\par ??\cf0             logger.Warn(message, [error])\par ??        \cf1 End\cf0  \cf1 If\par ??\cf0     \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Public\cf0  \cf1 Shared\cf0  \cf1 Sub\cf0  LogWarning(\cf1 ByVal\cf0  message \cf1 As\cf0  \cf1 String\cf0 , _\par ??                                 \cf1 ByVal\cf0  user \cf1 As\cf0  IPrincipal, \cf1 ByVal\cf0  url \cf1 As\cf0  Uri, _\par ??                                 \cf1 ByVal\cf0  [error] \cf1 As\cf0  Exception)\par ??        SetOptionalParametersOnLogger(user, url)\par ??        LogWarning(message, [error])\par ??    \cf1 End\cf0  \cf1 Sub\par ??\par ??\cf0     \cf1 Private\cf0  \cf1 Shared\cf0  \cf1 Sub\cf0  SetOptionalParametersOnLogger(\cf1 ByVal\cf0  user \cf1 As\cf0  IPrincipal, \cf1 ByVal\cf0  url \cf1 As\cf0  Uri)\par ??        \cf5 'set user to log4net context, so we can use %X\{user\} in the appenders\par ??\cf0         \cf1 If\cf0  \cf1 Not\cf0  user \cf1 Is\cf0  \cf1 Nothing\cf0  \cf1 AndAlso\cf0  user.Identity.IsAuthenticated \cf1 Then\par ??\cf0             MDC.[Set](\cf4 "user"\cf0 , user.Identity.Name)\par ??        \cf1 End\cf0  \cf1 If\par ??\par ??\cf0         \cf5 'set url to log4net context, so we can use %X\{url\} in the appenders\par ??\cf0         MDC.[Set](\cf4 "url"\cf0 , url.ToString())\par ??    \cf1 End\cf0  \cf1 Sub\par ??End\cf0  \cf1 Class\par ??\par ??} --></p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<pre style="margin: 0px;"><span style="color: blue;">Imports</span> System.Security.Principal</pre>
<pre style="margin: 0px;"><span style="color: blue;">Imports</span> log4net</pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;"><span style="color: blue;">Public</span> <span style="color: blue;">Class</span> LogHandler</pre>
<pre style="margin: 0px;">    <span style="color: blue;">Const</span> _defaultApplicationLogger <span style="color: blue;">As</span> <span style="color: blue;">String</span> = <span style="color: #a31515;">"Application"</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Public</span> <span style="color: blue;">Enum</span> LogType</pre>
<pre style="margin: 0px;">        General</pre>
<pre style="margin: 0px;">        Notify</pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Enum</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Public</span> <span style="color: blue;">Shared</span> <span style="color: blue;">Sub</span> LogError(<span style="color: blue;">ByVal</span> message <span style="color: blue;">As</span> <span style="color: blue;">String</span>, <span style="color: blue;">ByVal</span> [error] <span style="color: blue;">As</span> Exception)</pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">        <span style="color: blue;">Dim</span> logger <span style="color: blue;">As</span> ILog = LogManager.GetLogger(_defaultApplicationLogger)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">If</span> <span style="color: blue;">Not</span> [error].InnerException <span style="color: blue;">Is</span> <span style="color: blue;">Nothing</span> <span style="color: blue;">Then</span></pre>
<pre style="margin: 0px;">            [error] = [error].InnerException</pre>
<pre style="margin: 0px;">        <span style="color: blue;">End</span> <span style="color: blue;">If</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">        <span style="color: blue;">If</span> logger.IsErrorEnabled <span style="color: blue;">Then</span></pre>
<pre style="margin: 0px;">            logger.Error(message, [error])</pre>
<pre style="margin: 0px;">        <span style="color: blue;">End</span> <span style="color: blue;">If</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Public</span> <span style="color: blue;">Shared</span> <span style="color: blue;">Sub</span> LogError(<span style="color: blue;">ByVal</span> message <span style="color: blue;">As</span> <span style="color: blue;">String</span>, _</pre>
<pre style="margin: 0px;">                                <span style="color: blue;">ByVal</span> user <span style="color: blue;">As</span> IPrincipal, <span style="color: blue;">ByVal</span> url <span style="color: blue;">As</span> Uri, _</pre>
<pre style="margin: 0px;">                                <span style="color: blue;">ByVal</span> [error] <span style="color: blue;">As</span> Exception)</pre>
<pre style="margin: 0px;">        SetOptionalParametersOnLogger(user, url)</pre>
<pre style="margin: 0px;">        LogError(message, [error])</pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Public</span> <span style="color: blue;">Shared</span> <span style="color: blue;">Sub</span> LogInfo(<span style="color: blue;">ByVal</span> message <span style="color: blue;">As</span> <span style="color: blue;">String</span>, <span style="color: blue;">ByVal</span> type <span style="color: blue;">As</span> LogType)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">Dim</span> logger <span style="color: blue;">As</span> ILog = <span style="color: blue;">Nothing</span></pre>
<pre style="margin: 0px;">        <span style="color: blue;">If</span> type = LogType.Notify <span style="color: blue;">Then</span></pre>
<pre style="margin: 0px;">            logger = LogManager.GetLogger(LogType.Notify.ToString)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">Else</span></pre>
<pre style="margin: 0px;">            logger = LogManager.GetLogger(_defaultApplicationLogger)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">End</span> <span style="color: blue;">If</span></pre>
<pre style="margin: 0px;">        <span style="color: blue;">If</span> logger.IsInfoEnabled <span style="color: blue;">Then</span></pre>
<pre style="margin: 0px;">            logger.Info(message)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">End</span> <span style="color: blue;">If</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Public</span> <span style="color: blue;">Shared</span> <span style="color: blue;">Sub</span> LogWarning(<span style="color: blue;">ByVal</span> message <span style="color: blue;">As</span> <span style="color: blue;">String</span>, <span style="color: blue;">ByVal</span> [error] <span style="color: blue;">As</span> Exception)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">Dim</span> logger <span style="color: blue;">As</span> ILog = LogManager.GetLogger(_defaultApplicationLogger)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">If</span> <span style="color: blue;">Not</span> [error].InnerException <span style="color: blue;">Is</span> <span style="color: blue;">Nothing</span> <span style="color: blue;">Then</span></pre>
<pre style="margin: 0px;">            [error] = [error].InnerException</pre>
<pre style="margin: 0px;">        <span style="color: blue;">End</span> <span style="color: blue;">If</span></pre>
<pre style="margin: 0px;">        <span style="color: blue;">If</span> logger.IsWarnEnabled <span style="color: blue;">Then</span></pre>
<pre style="margin: 0px;">            logger.Warn(message, [error])</pre>
<pre style="margin: 0px;">        <span style="color: blue;">End</span> <span style="color: blue;">If</span></pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Public</span> <span style="color: blue;">Shared</span> <span style="color: blue;">Sub</span> LogWarning(<span style="color: blue;">ByVal</span> message <span style="color: blue;">As</span> <span style="color: blue;">String</span>, _</pre>
<pre style="margin: 0px;">                                 <span style="color: blue;">ByVal</span> user <span style="color: blue;">As</span> IPrincipal, <span style="color: blue;">ByVal</span> url <span style="color: blue;">As</span> Uri, _</pre>
<pre style="margin: 0px;">                                 <span style="color: blue;">ByVal</span> [error] <span style="color: blue;">As</span> Exception)</pre>
<pre style="margin: 0px;">        SetOptionalParametersOnLogger(user, url)</pre>
<pre style="margin: 0px;">        LogWarning(message, [error])</pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">    <span style="color: blue;">Private</span> <span style="color: blue;">Shared</span> <span style="color: blue;">Sub</span> SetOptionalParametersOnLogger(<span style="color: blue;">ByVal</span> user <span style="color: blue;">As</span> IPrincipal, <span style="color: blue;">ByVal</span> url <span style="color: blue;">As</span> Uri)</pre>
<pre style="margin: 0px;">        <span style="color: green;">'set user to log4net context, so we can use %X{user} in the appenders</span></pre>
<pre style="margin: 0px;">        <span style="color: blue;">If</span> <span style="color: blue;">Not</span> user <span style="color: blue;">Is</span> <span style="color: blue;">Nothing</span> <span style="color: blue;">AndAlso</span> user.Identity.IsAuthenticated <span style="color: blue;">Then</span></pre>
<pre style="margin: 0px;">            MDC.[Set](<span style="color: #a31515;">"user"</span>, user.Identity.Name)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">End</span> <span style="color: blue;">If</span></pre>
<pre style="margin: 0px;"></pre>
<pre style="margin: 0px;">        <span style="color: green;">'set url to log4net context, so we can use %X{url} in the appenders</span></pre>
<pre style="margin: 0px;">        MDC.[Set](<span style="color: #a31515;">"url"</span>, url.ToString())</pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Class</span></pre>
<pre style="margin: 0px;"></pre>
</div>
</div>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"></div>
<p>Comments on LogHandler</p>
<ul>
<li>It&#039;s a pretty simple class which is easy to use. I could have added more wrapper methods with overload</li>
<li>The LogType enum defines whether the message should be notified (emailed) or not.</li>
<li>If I forget to set the level on the logger in the Log4Net.config, the logger.IsInfoEnabled will return false.</li>
<li>I am using the MDC class in the Log4Net framework to add the custom entries in the logged message for user and url (see Log4Net.config above)</li>
</ul>
<h3>Handling an error and notifying with success</h3>
<p>Sometimes when you know what could go wrong and you want to display a nice error message to the user, you could handle the error and display an errormessage to the user.</p>
<p>Example:</p>
<p><!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red163\green21\blue21;}??\fs20     \cf3 Private\cf0  \cf3 Function\cf0  CreateUser() \cf3 As\cf0  User\par ??        \cf3 Dim\cf0  userName \cf3 As\cf0  \cf3 String\cf0  = TextBoxUserName.Text\par ??        \cf3 Dim\cf0  password \cf3 As\cf0  \cf3 String\cf0  = TextBoxPassword.Text\par ??        \cf3 Try\par ??\cf0             \cf3 Dim\cf0  user \cf3 As\cf0  \cf3 New\cf0  User(userName, password)\par ??            LogHandler.LogInfo(\cf4 "Yahoo! User with username "\cf0  &amp; userName &amp; \cf4 " created."\cf0 , LogHandler.LogType.Notify)\par ??            \cf3 Return\cf0  user\par ??        \cf3 Catch\cf0  iunex \cf3 As\cf0  InvalidUserNameException\par ??            Tools.AlertError(Page, iunex)\par ??            LogHandler.LogError(\cf4 "Error creating user with username "\cf0  &amp; userName, HttpContext.Current.User, HttpContext.Current.Request.Url, iunex)\par ??        \cf3 Catch\cf0  ipex \cf3 As\cf0  InvalidPasswordException\par ??            Tools.AlertError(Page, iunex)\par ??            LogHandler.LogError(\cf4 "Error creating user with password "\cf0  &amp; password, HttpContext.Current.User, HttpContext.Current.Request.Url, ipex)\par ??        \cf3 End\cf0  \cf3 Try\par ??\cf0     \cf3 End\cf0  \cf3 Function\par ??} --></p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black;">
<pre style="margin: 0px;"><span style="color: blue;">Private</span> <span style="color: blue;">Function</span> CreateUser() <span style="color: blue;">As</span> User</pre>
<pre style="margin: 0px;">    <span style="color: blue;">Dim</span> userName <span style="color: blue;">As</span> <span style="color: blue;">String</span> = TextBoxUserName.Text</pre>
<pre style="margin: 0px;">    <span style="color: blue;">Dim</span> password <span style="color: blue;">As</span> <span style="color: blue;">String</span> = TextBoxPassword.Text</pre>
<pre style="margin: 0px;">    <span style="color: blue;">Try</span></pre>
<pre style="margin: 0px;">        <span style="color: blue;">Dim</span> user <span style="color: blue;">As</span> <span style="color: blue;">New</span> User(userName, password)</pre>
<pre style="margin: 0px;">        LogHandler.LogInfo(<span style="color: #a31515;">"Yahoo! User with username "</span> &amp; userName &amp; <span style="color: #a31515;">" created."</span>,
                           LogHandler.LogType.Notify)</pre>
<pre style="margin: 0px;">        <span style="color: blue;">Return</span> user</pre>
<pre style="margin: 0px;">    <span style="color: blue;">Catch</span> iunex <span style="color: blue;">As</span> InvalidUserNameException</pre>
<pre style="margin: 0px;">        PageTools.DisplayError(Page, iunex)</pre>
<pre style="margin: 0px;">        LogHandler.LogWarning(<span style="color: #a31515;">"Error creating user with username "</span> &amp; userName, iunex)</pre>
<pre style="margin: 0px;">    <span style="color: blue;">Catch</span> ipex <span style="color: blue;">As</span> InvalidPasswordException</pre>
<pre style="margin: 0px;">        PageTools.DisplayError(Page, ipex)</pre>
<pre style="margin: 0px;">        LogHandler.LogWarning(<span style="color: #a31515;">"Error creating user with password "</span> &amp; password, ipex)</pre>
<pre style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Try
    Return Nothing</span></pre>
<pre style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Function</span></pre>
</div>
<p>Comments on CreateUser:</p>
<ul>
<li>If successful, a notification is sent by email by using the LogInfo method and using LogHandler.Logtype.Notify</li>
<li>The User class will throw InvalidUserNameException or InvalidPasswordException in the credentials are invalid. I wish to display the errors to the user instead of displaying a general error page. In real life I would probably use some validation before calling the User constructor, but this is only an example.  <img src='http://hamang.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </li>
<li>In addition to displaying the error to the user, the error is logged as a warning.This means it will be logged, but no email will be sent to the mailbox as this is not an error in the application.</li>
<li>All other exceptions raised when creating the user will be caught in Application_Error in Global.asax and logged there.</li>
</ul>
<h3>Loginformation</h3>
<p>Ok, now I have all the code I need to do decent logging. So what do I expect to see in the logfiles?</p>
<p>When building the application in DEBUG mode I will see the following in the logfile:</p>
<pre>2008-12-11 16:56:24,453 [14] INFO  Application (null) (null) - ============================
2008-12-11 16:56:24,468 [14] INFO  Application (null) (null) -     Starting application
2008-12-11 16:56:24,468 [14] INFO  Application (null) (null) - ============================
2008-12-11 16:56:25,937 [14] WARN Application 3DX5G3J\knuth http://localhost/fdb/default.aspx -
                                  Error creating user with username Knut Hamang
DAL.InvalidUserNameException: Username is already in use! Please select another username.
   at DAL.User..ctor(String username, String password) in C:\Knut\code\Repository\Internal_Systems\fdb\trunk\DAL\User.vb:line 97
   at fdb.default.CreateUser() in C:\Knut\code\Repository\Internal_Systems\fdb\trunk\Web\default.aspx.vb:line 69</pre>
<p>Building in RELEASE  mode I get the following information:</p>
<pre>2008-12-11 16:59:21,406 [14] INFO  Application (null) (null) - ============================
2008-12-11 16:59:21,421 [14] INFO  Application (null) (null) -     Starting application
2008-12-11 16:59:21,421 [14] INFO  Application (null) (null) - ============================
2008-12-11 16:59:22,812 [14] WARN Application 3DX5G3J\knuth http://localhost/fdb/default.aspx -
                             Error creating user with username Knut Hamang
DAL.InvalidUserNameException: Username is already in use! Please select another username.
   at DAL.User..ctor(String username, String password)
   at fdb.default.CreateUser()</pre>
<p>The difference is the stacktrace. I get the stacktrace in both cases, but I also get the line numbers in DEBUG mode. I can still read the trace and locate the method in the file that throws the error. The conclusion is that I get enough information to trace and fix the error, if there is one.</p>
<p>Please leave any comments on the configuration, and feel free to discuss different logging strategies for Web Applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://hamang.net/2008/12/12/using-log4net-in-web-applications-a-reallife-example/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>A great article on understanding ViewState</title>
		<link>http://hamang.net/2006/06/16/a-great-article-on-understanding-viewstate/</link>
		<comments>http://hamang.net/2006/06/16/a-great-article-on-understanding-viewstate/#comments</comments>
		<pubDate>Fri, 16 Jun 2006 09:33:33 +0000</pubDate>
		<dc:creator>Knut Hamang</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[This is as important to ASP.NET developers as it is to developers creating server controls (both user controls and custom controls). ViewState is difficult to understand, but when used correctly, it&#039;s very powerful. Read and learn: http://infinitiesloop.blogspot.com/2006/03/truly-understanding-viewstate.html]]></description>
			<content:encoded><![CDATA[<p>This is as important to ASP.NET developers as it is to developers creating server controls (both user controls and custom controls). ViewState is difficult to understand, but when used correctly, it&#039;s very powerful.</p>
<p>Read and learn: <a href="http://infinitiesloop.blogspot.com/2006/03/truly-understanding-viewstate.html">http://infinitiesloop.blogspot.com/2006/03/truly-understanding-viewstate.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://hamang.net/2006/06/16/a-great-article-on-understanding-viewstate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Override the rendering of the ASP.NET 2.0 controls.</title>
		<link>http://hamang.net/2006/03/31/override-the-rendering-of-the-aspnet-20-controls/</link>
		<comments>http://hamang.net/2006/03/31/override-the-rendering-of-the-aspnet-20-controls/#comments</comments>
		<pubDate>Fri, 31 Mar 2006 08:18:26 +0000</pubDate>
		<dc:creator>Knut Hamang</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[In April, the ASP.NET team will ship examples on how to use ControlAdapters for the ASP.NET 2.0 controls. This is a really good idea, because very few people knows how to override the rendering of the standard ASP.NET 2.0 controls. The ControlAdapters allows the developers to render the controls in a really nice way instead of using tables, which [...]]]></description>
			<content:encoded><![CDATA[<p>In April, the ASP.NET team will ship examples on how to use ControlAdapters for the ASP.NET 2.0 controls. This is a really good idea, because very few people knows how to override the rendering of the standard ASP.NET 2.0 controls. The ControlAdapters allows the developers to render the controls in a really nice way instead of using tables, which seems to be the Microsoft way. For instance, the menu control can be rendered with &lt;ul&gt;&lt;li&gt; tags and be customized with CSS classes. This is a really nice feature that few people know about.</p>
<p><a href="http://weblogs.asp.net/scottgu/archive/2006/03/30/441465.aspx" target="_blank">Check out ScottGu&#039;s blog for more information about this.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://hamang.net/2006/03/31/override-the-rendering-of-the-aspnet-20-controls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

