Tuesday, 10 March 2009

log4net logging causing the computer to beep

Whilst working on my current project, I came across a rather annoying problem:

During service calls, we log the input and output params. When we started to integration test the system and a user performed a search, a beeping could be heard from the computer.
This, obviously caused some distress to anyone near the PC as it was constant and annoying.

As this was only being heard during a search service call the first, and very incorrect thought, was that the search was very poor and sql server was struggling.

After 5 seconds of debugging I found the following line to be the cause of the problem:

logger.Info(GetExitMessage(invocation, returnValue, executionTimeSpan));

We were using reflection to generate our message and log4net as the logger. I was still unsure of what the problem was.

I looked at the message that was being generated and replicated the problem in a simple console application. I eventually got the following piece of code to reproduce the mysterious beep:

    1 using System;

    2 using log4net;

    3 

    4 namespace log4netProblem

    5 {

    6     class Program

    7     {

    8         static ILog _logger = LogManager.GetLogger(typeof(Program));

    9 

   10         static void Main(string[] args)

   11         {

   12             try

   13             {

   14                 log4net.Config.BasicConfigurator.Configure();

   15                 string s = "•";

   16                 _logger.Info(s);

   17             }

   18             catch (Exception e)

   19             {

   20                 Console.Write(e);

   21             }

   22             finally

   23             {

   24                 Console.WriteLine("Press any key to exit...");

   25                 Console.ReadKey();

   26             }

   27         }

   28     }

   29 }



Yes yes yes, I see the problem now. "•" was the shortcut for making a console beep.

It turns out that in my haste of setting up the appenders in the web application, I had left the console appender in there and the PC wasn't about to catch fire at all.

All I can say is oops.

Submit this story to DotNetKicks Shout it

No comments:

Post a Comment