Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

HomeDev GuideRecipesAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Log with log4net

Introduces logging using log4net in Optimizely Content Management System (CMS) and Optimizely Customized Commerce.

📘

Note

You should read the introduction at the Log4net website for a better understanding before reading this topic.

When you deploy the EPiServer.Logging.Log4Net package in your solution, any logging by the system uses the log4net framework.

Logging levels

Logging assigns the following levels according to priority level, with OFF having the highest value and ALL the lowest value:

  1. OFF
  2. FATAL
  3. ERROR
  4. WARN
  5. INFO
  6. DEBUG
  7. ALL

Enable logging

You control logging from EPiServerLog.config. Place it in the same directory as the application’s web.config file. Separate the logging configuration from web.config if you want to enable logging when the application has entered a bad state and you must change and save the configuration file. If the information is in web.config the web application is restarted when you save web.config, possibly clearing the cause of the problem you wanted to log. Keeping the log configuration separate from web.config eliminates this problem.

A log configuration file may look like this:

<log4net>
  <appender name="ErrorAppender" type="log4net.Appender.FileAppender" >
    <file value="e:\\episerverlogfiles\\log-file.txt" />
    <appendToFile value="true" />
    <layout type="log4net.Layout.PatternLayout">
       <conversionPattern value="%d [%t] %l - %m%n" />
    </layout>
 </appender>
 <root>
   <level value="WARN" />
   <appender-ref ref="ErrorAppender" />
 </root>
</log4net>

If you want to enable full logging, change the level value in the root tag to ALL; this gives you a lot of data.

Disable logging

You have the following ways to disable active logging:

  • Set the level to OFF in EPiServerLog.config.
  • Remove the file and restart the website by saving the system settings orweb.config again, killing the process or resetting IIS. It is not enough to remove the file because you must restart the website to disable logging.

Log site information

The site information is primarily concerned with logging various problems and unusual events. You should monitor events with log level WARN and above. Lower-level events get information to track down specific errors or bugs. You can enable full logging to a RollingFileAppender in the development environment to check what has happened in Optimizely Content Management System (CMS) if a specific problem occurs (see the log4net documentation). However, you would probably want to monitor WARN events and higher during regular production use.

Exceptions are logged with the complete stack trace to let you track down exception errors. Be aware that exceptions are expensive in terms of performance. Avoid writing code that generates exceptions as part of the normal program flow.

Organize log file storage

For a production site, you must have a policy regarding log files to avoid problems, such as exposing log files on your website, filling up a system partition with log data, and so on. The CMS logging functions monitor the health of your Web application. They should not (under normal operation) cause excessive logging, as long as you do not enable logging of events below the WARN level.

📘

Note

If you are using remoting, UDP appenders or any type of appender that does not write log files to the local drives, the actual storage of log data will probably not happen on the Web server, although other restrictions may apply.

CMS recommends the following ways to store log files. You must have at least write permission for the directory that you want to log to for the account that you are using for your website.

  • Store log files outside the folder structure exposed by the web server. If you installed the CMS application in the C:\EPiServer\EPiServerSite1 folder, do not store your log files in the C:\EPiServer\EPiServerSite1\App_Data folder (default storage). Depending on web server configuration and file access rights, this could expose your logs to any visitor to your website.
  • Do not store log files on the system partition. If your web server has the operating system installed on the C: drive, store the log files on another drive. Even though CMS’s log functions should not cause large log files during normal operation, the log files may grow large if you enable full debugging. If the logging takes all free space on your system partition, your website may become unavailable until you resolve the situation.