EPiServer log: More configuration tips

Nicklas Israelsson shared in his blog how you can exclude some name spaces from the EPiServer log to reduce the noise while debugging. A very useful tip! I would like to share how I use logging to collect exceptions (and debug info) in production.

How to setup production logging of Exceptions in EPiServer

Paste the example below into the EPiServerLog.config file in the root of your EPiServer application.

<?xml version="1.0" encoding="utf-8"?>
<log4net>

  <!-- Appender with one new log file per day -->
  <appender name="fileLogAppender"
            type="log4net.Appender.RollingFileAppender" >
    <file value="E:\EPiServerLog\www.example.com" />
    <encoding value="utf-8" />
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
    <appendToFile value="true" />
    <rollingStyle value="Date" />
    <staticLogFileName value="false" />
    <datePattern value=".yyyyMMdd.'log'" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date %level [%thread] %type.%method - %message%n" />
    </layout>
  </appender>

  <!-- Log page publish to find editor related errors. -->
  <logger name="EPiServer.DataAccess.PageSaveDB">
    <level value="DEBUG" />
  </logger>

  <!-- Removing all rows coming from OptimisticCache -->
  <logger name="EPiServer.Core.OptimisticCache" additivity="false">
    <level value="Off"/>
    <appender-ref ref="fileLogAppender" />
  </logger>  

  <!-- Send all errors to file. Level: Off, Fatal, Error, Warn, Info, Debug, All -->
  <root>
    <level value="Error" />
    <appender-ref ref="fileLogAppender" />
  </root>
</log4net>

TODO: You need to adjust the file-tag ("E:\EPiServerLog\") to an existing folder where the account used by your asp.net application are allowed to write. Also notice that backslash must be escaped.

lockingModel

Notice that this differs from what is shipped in the default EPiServerLog.config file (that does not work AFAIK).

file, rollingStyle, staticLogFileName, datePattern

These tags configures one file per day in the folder specified by the file-tag. I prefer to set staticLogFileName to false even if true might get some better performance.

level

Change level from Error to Debug or All if you need more data when you debug. Do remember to change it back to Error when you are done because your files grow fast and using reflection to find type and method steals some CPU-time, too.

Bookmark and Share

Tags: ,

  1. Mattias Lövström’s avatar

    I should want to change the value OFF to WARN (the recommended deployment settings for EPiServer, so you don’t hide any dangerous logs – which you absolutely want to log in a development environment)

    I think it’s a good idea to exclude the annoying loggers:
    Microsoft.Samples.Runtime.Remoting.Channels.Pipe.DBG
    EPiServer.DataAbstraction.ScheduledJob
    EPiServer.Web.FriendlyUrlRewriteProvider
    EPiServer.Web.UrlRewriteModuleBase
    EPiServer.Web.UrlRewriteModule
    EPiServer.Web.FriendlyHtmlRewriteToExternal
    EPiServer.Web.PermanentLinkMapStore
    EPiServer.Core.PageProviderBase
    EPiServer.Web.WebControls.Property
    EPiServer.Web.Hosting.VirtualPathVersioningProvider
    I have an example on my EPiServer notebook
    http://www.epiwiki.se/developing/log4net/readable-episerver-debug-log

    Reply

    1. Fredrik Haglund’s avatar

      Thanks for sharing!

      Reply