Take the community feedback survey now.

Steve Celius
Apr 26, 2010
  10552
(0 votes)

log4net Tips: Do not declare a logger in Global.asax.cs

If you declare your own logger in Global.asax.cs (for the Global class) you will effectively turn off all log4net logging for the entire site.

Like this:

using log4net;
using System.Reflection;
...
public class Global : EPiServer.Global
{
// Very bad idea
static readonly ILog _log = log4net.LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
...
}

Seems like not everyone knows about this – so consider yourself warned!

Apr 26, 2010

Comments

Sep 21, 2010 10:33 AM

So if we shouldn't declare a log4net logger here, is it possible to still use log4net in global.asax? I'd like to log un-handled exceptions from this class.
/ Striker

Please login to comment.
Latest blogs
A day in the life of an Optimizely OMVP - Creating a blazor add-on for CMS 12

Hello and welcome to another instalment of a day in the life of an Optimizely OMVP. In this post I will be covering how to create a blazor based...

Graham Carr | Oct 14, 2025

AI Tools, MCP, and Function Calling for Optimizely

You can now integrate AI Tools, Model Context Protocol (MCP), and function calling with Optimizely CMS, allowing editors to engage with actual,...

Luc Gosso (MVP) | Oct 14, 2025 |

Optimizely Forms : Setup, Configuration and Submission

I have exploring Optimizely Forms recently –  Installed NuGet package to enable Optimizely Forms, created a Contact Us Form and placed in a landing...

Madhu | Oct 13, 2025 |

Building a Discovery-First MCP for Optimizely CMS – Part 1 of 4

This post kicks off a four-part series on how we’re evolving the Optimizely Model Context Protocol (MCP). The project is still in beta and open...

Johnny Mullaney | Oct 13, 2025 |