Useful information for writing HTML email newsletters

I recently had to write an HTML email newsletter using Tim’s excellent mail engine package for Umbraco.  One of the issues is cross email client testing,  I found two sites that were extremely useful in clearing up any cross client issues:

Enjoy!

Integrating log4net into Umbraco site.

Following on from Lee Kelleher’s excellent post on integrating ELMAH into Umbraco I have managed to plug in log4Net.  This technique could also be used to plugin anything else that needs access to events in global.asax for example a dependancy injection library (I will at some point blog about wiring up Ninject into Umbraco).  If you want to use log4Net with Umbraco here is what you need todo:

  • Download log4Net
  • Create a  project with class that inherits from HttpWebApplication class mine looks like:
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace Log4net4Umbraco
    {
        public class Logger : System.Web.HttpApplication
        {
    
            private static log4net.ILog log = log4net.LogManager.GetLogger(typeof(Logger));
    
            public Logger()
    		{
    			InitializeComponent();
    		}
    
            protected void Application_Start(Object sender, EventArgs e)
            {
                // Application start-up code goes here.
                log4net.Config.XmlConfigurator.Configure();
    
                log.Debug("Fired up logger in application_start");
            }
    
            protected void Application_End(Object sender, EventArgs e)
            {
    
                log.Debug("closed logger in application_end");
                log4net.LogManager.Shutdown();
    
            }
    
     	    protected void Application_Error(object sender, EventArgs e)
     	    {
     	        // Code that runs when an unhandled error occurs
    
     	        log.Error("Unhandled exception", Context.Error);
    
     	    }
    
            private void InitializeComponent()
            {
    
            }
    
        }
    }
    
    
  • Remove App_global.asax.dll from your website bin. This file is part of umbraco distribution, it has events wired up for Umbraco basically writes start up message to umbraco log. If this is not removed then site will not fire up.
  • Add the following lines to the web.config under configsections
      <configSections>
          <section  name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
      </configSections>
      <log4net configSource="config\log4net.config" />
    
  • Under the config directory I added a config file called log4net.config for all the available options see the log4net documentation.
    <?xml version="1.0" encoding="utf-8" ?>
      <log4net>
    
     	    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
    <threshold value="ALL"/>
     	      <file value="C:\\Inetpub\\mysite\\data\\Logs\\site.log" />
     	      <appendToFile value="true" />
     	      <rollingStyle value="Date" />
     	      <datePattern value="yyyyMMdd" />
     	      <layout type="log4net.Layout.PatternLayout">
     	        <conversionPattern value="%date &#91;%thread&#93; %-5level %logger &#91;%property{NDC}&#93; - %message%newline" />
     	      </layout>
     	    </appender>
    
    		<root>
    				<appender-ref ref="RollingLogFileAppender"/>
    		</root>
    
    </log4net>
    
  • Copy the dll and log4net dlls to the bin of your site
  • Create a new global.asax file if you don’t already have one.  Point the file to the dll you created so in my case I have
    <%@ Application Codebehind="logger.cs" Inherits="Log4net4Umbraco.Logger" %>
    

Now when the application fires up log4net is initialized.  In my usercontrols or xslt extensions all I need to do to start logging is add code like

private static log4net.ILog log = log4net.LogManager.GetLogger(typeof(MyClass));

public void SomeMethod(){
     log.debug("blah blag");
}

Its all well and good logging you need a way to view the logs. So you can use one of the following to view the logs via a dashboard in Umbraco:

urlrewriting application start issue

My colleague Paul Symes Adam Perry recently discovered a recurring error in the umbraco log,

“Item has already been added. Key in dictionary: ‘RegEx’ Key being added: ‘RegEx'”

sometimes he would also get the yellow screen of death.  He managed to track it down to an issue with application start and UrlRewritingNet dll.  The issue is detailed here on google UrlRewritingNet forum.

According to the post UrlRewritingNet 2.1 will have the fix, however we are still on 2.0.6 which is used by Umbraco.  I have downloaded latest source of UrlRewritingNet and updated the code.  You can get updated source and binary here

New search option for umbraco site

There are currently three search implementations for umbraco:

  1. XSLT search
  2. umbSearch (Lucene.net)
  3. Microsoft search server

I would like to propose a 4th alternative Thunderstone webinator. Its a tool I used many moons ago with another CMS.  It comes in 2 flavours hosted or host yourself.  There is a free version it has restriction of 10,000 documents (see full version feature matrix) and only indexes html pages.  I would recommend going down the hosted route, basically you create an account on the site and then point it to your website.  The search engine is a crawler so all your content needs to be linked up. If you have a good site map then most if not all your content will be linked. After crawl you get your own personal url that looks like http://mysite.master.com/texis/master/search so you can create your own form that posts to that page.

The admin interface will let you style up your search results page. The results page has % relevance and find similar functionality, you can see a working result page here. I am not advocating this solution over the other excellent solutions already available I just think this is a nice alternative to give fast, rich search functionality very quickly.