Steve Celius
Apr 26, 2010
  10204
(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
Creating an Optimizely CMS Addon - Adding an Editor Interface Gadget

In   Part One   of this series, I covered getting started with creating your own AddOn for Optimizely CMS 12. This covered what I consider to be an...

Mark Stott | Aug 30, 2024

Configure your own Search & Navigation timeouts

The main blog Configure your own Search & Navigation timeouts was posted for years but you need copy the code to your application. We now bring tho...

Manh Nguyen | Aug 30, 2024

Joining the Optimizely MVP Program

Andy Blyth has been honoured as an Optimizely MVP, recognising his contributions to the Optimizely community. Learn how this achievement will enhan...

Andy Blyth | Aug 29, 2024 | Syndicated blog

Welcome 2024 Summer OMVPs

Hello, Optimizely community! We are thrilled to announce and welcome the newest members to the Optimizely Most Valuable Professionals (OMVP) progra...

Patrick Lam | Aug 29, 2024