Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
This topic provides developers and system administrators with an introduction to the standard implementation of the Logging API using log4net in the Episerver platform, including CMS and Commerce. It describes how to configure logging in Episerver, and how to interpret the logged information, plus some best practices. When you deploy the EPiServer.Logging.Log4Net package in your solution, any logging by the system uses the log4net framework.
Note: You should read the introduction at the Log4net website for a better understanding before reading this topic.
The following levels of logging are assigned according to priority level, with OFF having the highest value and ALL the lowest value:
You control logging from EPiServerLog.config. Place it in the same directory as the application’s web.config file. The logging configuration is separated from web.config in case you want to enable logging when the application has entered a bad state and you have to 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 for the problem that you wanted to log. Keeping the log configuration separate from web.config eliminates this problem.
A very simple 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, simply change the level value in the root tag to ALL; this gives you a lot of data.
You have the following ways to disable active logging:
The site information is primarily concerned with logging various problems and unusual events. Basically you should always monitor events with log level WARN and above. Events with lower levels are primarily intended to get information to track down specific errors and/or bugs. A developer might want to enable full logging to a RollingFileAppender (see the log4net documentation) in the development environment to check what has happened in Episerver if a specific problem occurs. However, during regular production use, you would probably want to just monitor WARN events and higher.
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.
For a production site, it is essential to 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 Episerver logging functions are intended to monitor the health of your web application and 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.
Last updated: Sep 21, 2015