1

Using Elmah in EPiServer

Elmah is a great logging tool to discover unhandled exceptions in you web site. If you haven't used it yet; just add the elmah.dll to your project and couple of settings in your web.config. The log entries is default stored in memory on the server, but you can also choose to store the entries in a permentant store like xml files, a database, twitter etc. I have extended elmah with two new episerver log sinks; Dynamic Data Store and VPP. To get hold of them you can download the binaries here og you get hold of the source code at github.

Dynamic Data Store

This sink stores the log entries in database using EPiServer Dynamic Data Store framework. There is no need to add extra configuration needed to make this log sink work. To enable this log sink just add the following configuration.

<elmah>   
    <errorLog type="JarleF.EPiElmah.DDSErrorLog, JarleF.EPiElmah" />
</elmah>
 

VPP

This log sink stores the log entries as xml inside a EPiServer VPP folder. The advantage of using this over the build in xml log sink is that this sink stores the entries in a central location which is accessible from all episerver installations in a cluster. This method leverages EPiServers Index Service to find the logged events in the Elmah report. This requires that the EPiServer Index Service is enabled and is configured to crawl the VPP folder. It is also better to use a native VPP folder over a versioned folder as it has less overhead. The VPP folder must also have the "bypasssecurity" flag set to "true" since the log entries is generated in the visitors security context.

Add the log VPP folder like this:

<add showInFileManager="true" 
     virtualName="SystemFiles"      
     virtualPath="~/SystemFiles/" 
     bypassAccessCheck="true" 
     name="SystemFiles"      
     type="EPiServer.Web.Hosting.VirtualPathNativeProvider,EPiServer"
     indexingServiceCatalog="Web"      
     physicalPath="C:\EPiServer\VPP\EPiDemo\SystemFiles" />  
Enable the log sink like this (notice the logpath):
<elmah>        
   <errorLog type="JarleF.EPiElmah.VPPErrorLog, JarleF.EPiElmah"
             logPath="~/SystemFiles/Log" />
</elmah>

Protecting and viewing the Elmah report

If you don't want everyone to have access to your elmah reports simply move the elmah httphandler into the EPiServer CMS Admin location in your web.config. This ensure only users that has access to the administration rights to view the log.
<location path="secure/CMS/admin">    
    ...    
    <system.webServer>      
        <handlers>        
            <add name="Elmah" 
                 verb="POST,GET,HEAD"              
                 path="elmah.axd" 
                 type="Elmah.ErrorLogPageFactory, Elmah" />      
        </handlers>          
    </system.webServer>
</location>
A final though is to make the elmah report easy accessible for the web admins. To do you can simply add the following plugin class.
 
[GuiPlugIn(DisplayName = "Error Report", 
           Area = PlugInArea.AdminMenu, 
           Url="~/secure/cms/admin/elmah.axd")]
public class ErrorReport
{
}
The result lookes something like this
 
image
 image

Comments (1) -

Frederik Vig says: 11/1/2010 9:06:49 AM
Frederik Vig

Excellent work Jarle! Just what I needed for a customer Smile.

Frederik

Add comment




biuquote
Loading


Disclaimer

© Copyright 2009, Jarle Friestad. The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Widget Twitter not found.

Root element is missing.X

Month List