A simple trick to get more information out of the Sitecore logs

Recently, I was struggling with one particular Sitecore site that was taking too much time to load in my development environment. Sometimes I would think that it just got stuck and then I would try restarting the application pool or even running an iisreset.

This article shows a quick tip if you want to get more out of the Sitecore logs by doing a simple trick: enabling the DEBUG level.

Still on that particular Sitecore site, whenever I looked at the Sitecore logs, I noticed that the log wrote something like the following and then it stopped.

ManagedPoolThread #3 15:58:25 INFO  Trying to load XML 
configuration /App_Config/Security/Domains.config

Or sometimes, it would stop at the following entry.

12968 15:40:30 INFO  HttpModule is being initialized

That would make me think that there was something wrong with the Domains.config file or with some HttModule during the initialization.

Then I remembered that Sitecore.Logging works similarly to log4net, and by default Sitecore.Logging uses the INFO logging level.

Just for the sake of curiosity, altough Sitecore.Logging uses the same namespace as log4net and works similar to it, Sitecore.Logging has no dependency on log4net. Having that said, some features in log4net are not available in Sitecore.Logging. Please, see this question I posted on SitecoreStackExchange for more information.

All I had to do in order to get more information was to enable the DEBUG level. To enable DEGUG level, just add a patch file with the following content.

After enabling that, I could get more information out of the Sitecore logging and see that my Sitecore instance was still running some process and logging information but on a DEBUG level.

ManagedPoolThread #3 15:58:25 INFO  Trying to load XML configuration /App_Config/Security/Domains.config
10684 15:58:25 DEBUG [Sitecore Mvc]: Profile > Method InitializeRoutes.RegisterAreas - duration 2053ms
10684 15:58:25 DEBUG [Sitecore Mvc]: PrecompiledViewAssembly (Sitecore.Mvc) loaded, contains 0 CSHTML mappings
10684 15:58:25 DEBUG [Sitecore Mvc]: PrecompiledViewAssembly (Sitecore.Speak.Components.Web) loaded, contains 112 CSHTML mappings
10684 15:58:25 DEBUG [Sitecore Mvc]: PrecompiledViewAssembly (Sitecore.Speak.Web) loaded, contains 193 CSHTML mappings

What was wrong with that site? Well… let’s say that it is still a work in progress…

2 thoughts on “A simple trick to get more information out of the Sitecore logs

  1. Be careful with enabling DEBUG. Although great for lots of detail, it’ll will kill your server since all the additional logging does have an inherent cost. I’ve had local systems hang for several minutes due to (accidentally) setting this.

    > Just for the sake of curiosity, altough Sitecore.Logging uses the same namespace as log4net and works similar to it, Sitecore.Logging has no dependency on log4net.

    That’s not quite true. Sitecore *uses* log4net, except they have wrapped it in their own custom implementation, to allow the “new log file on app restart” functionality and to allow file name token parameters such as “{date}” for exmaple. If you take a look in “Sitecore.Logging.dll” using dotPeek then you’ll see all the same log4net namespaces, the issue is it’s a very old version (v1.2 i believe) and it’s the same version that’s been used since SC6. This leads to a problem when trying to use some of the newer features or other common libraries that require newer versions 😦

    Liked by 1 person

  2. True. We must be very careful with enabling DEBUG in environments that are not our local machine unless it is extremely necessary. Thanks for clarifying.

    By *Sitecore.Logging has no dependency on log4net* I meant that you won’t find the log4net assembly being referenced by the *Sitecore.Logging* (lognet.dll it is not even present in the assembly list nor in the /bin of the installation folder). That brings the problem that you mentioned about having an old version of the log4net replicated in “Sitecore.Logging”.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s