Question : Multi-threading log4net error

I'm trying to use log4net in multithreading in a web application, but it's giving me the following error:

"No log4net appenders defined in the config file"

This only happens if I have concurrent users, and not with new users (by using a stresstest).

I'm using a class that's inherit the the log4net class. See code snippet for details.

Can someone tell me what i'm doing wrong?

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
public class DbInteraction : Logger
{
   //functions defined here
}

public class Logger
    {
        internal static ILog log;

        internal Logger()
        {
            if (ConfigurationSettings.AppSettings["log4net.config_path"] == null)
            {
                throw new Exception("log4net config file not defined in web.config (key should be: log4net.config_path)");
            }

            log = LogManager.GetLogger(this.GetType());
            FileInfo configFile = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + ConfigurationSettings.AppSettings["log4net.config_path"].ToString());

            if (!configFile.Exists)
            {
                throw new Exception(String.Format("log4net config file doesn't exist, searched for: {0}", configFile.FullName));
            }

            //log4net.Config.XmlConfigurator.Configure(configFile);

            if (log.Logger.Repository.GetAppenders() == null || log.Logger.Repository.GetAppenders().Length == 0)
            {
                throw new Exception("No log4net appenders defined in the config file");
            }

        }

    }

Answer : Multi-threading log4net error

Your checks if the file exists are causing the problems. The file-system locks it temporary, which will cause problems if two instances check it at the same time. Rather put these checks in the Application_Start-event of your global,asax, that should prevent any unwanted locks.
Random Solutions  
 
programming4us programming4us