In this tutorial, you will learn about some advanced logging tips when using Episerver CMS to power your website. Over the years I've seen some pretty funky stuff done with logging and Episerver. After doing a recent performance review on a site, every page load was wasting up to 2 seconds just logging stuff, madness! To hopefully save someone else from going down a bad path, I'd thought I'd write down some tips to try and prevent these types of mistakes from happening. If you want to learn more about Episerver logging, read on!

Logging To Different Files

First up, it is pretty common to write your custom error logs into different files. One common situation where I've implemented multiple logs is around scheduling. Having all the logs generated by an Episerver scheduled task written into its own log file will make debugging easier. It's a lot cleaner and easier to spot bugs in long-running tasks when they are separated from your normal Episerver logs. If you need to do this, you DO NOT need to write any code. You can write different errors to different log files through configuration within the episerver.config file, more information here.

Do Not Write Your Own Custom Log4Net Implementation

Episerver uses Log4Net as the logging framework. Log4Net can be customised using a custom Log4Net appender. I do not recommend that you take this path. You definitely don't have to write custom code to configure how things are logged when you use Episerver. It is possible to write a custom Log4Net appender, however, it is easier to use the out-of-the-box Episerver appender and configure it correctly instead! Even if you want to write your logs to a database, this can all be done within the configuration. So far I've yet to bump into a strong enough reason why you need to write your own custom log appender, so why bother writing custom code when you do not need to!

Logging Too Much Will Slow Down Your Website

You can tell Log4Net how much data Episerver should log, easily. Like most things, the more work the appender has to perform, the longer it will take to run. The logger it takes, the more your page performance will be affected. For best performance, Log4Net appenders should be set to 'WARN' on your live website. This can be checked within episerverlog.config. In this file, ensure that All, Debug, or Info is not set as against an appender, as this will affect site performance.

Internal Log4Net Debugging

It can be pretty easy to make a typo when configuring episerverlog.config. if you do this nothing will get logged. If you find yourself in this situation, you can enable the internal Log4Net logging to help you troubleshoot what's gone wrong. To enable the internal Log4Net debugger, within your web.config in the AppSettings makes sure log4net.Internal.Debug is enabled:

To set where these logs files are written, there's a section within the system.diagnosis section within the web.config:

If you enable internal logging, DO NOT PUSH THESE CHANGES TO YOUR LIVE ENVIRONMENT! Enabling these logs is good for troubleshooting Log4Net configuration issues, it should not be run on your live website as performance will be severely impacted. After you are happy the log files are writing correctly, turn it off!

Make Your Logs Easily Visible

If you are running your website in DXC, Azure etc.. you want to ensure your logs are easily visible. If you need to RDP onto a server to look at your logs, you've not been as efficient as you could be. If you use a tool like Stackify, you can ensure Your Episerver Logs are appearing within the Stackify dashboard by installing the Stackify Log4Net NuGet package within your Episerver website. All the logs can be shipped to the cloud.


That's it, this concludes my complete list of Episerver logging tips. Happy Coding 🤘