Are your appenders outputting any kind of special variables like the ThreadId? 
Does the freeze occur if the background thread is writing to a MemoryAppender 
or a  NullAppender?

This code logged correctly for me:

public partial class Edit : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Thread thread = new Thread(ClassCreatedInNewThread.Create);
        thread.Start();
    }
}

public class ClassCreatedInNewThread
{
    private static readonly ILog log = 
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

    public ClassCreatedInNewThread()
    {
        log.Info("ClassCreatedInNewThread Constructor");
    }

    public void Info(string message)
    {
        log.Info(message);
    }

    public static void Create()
    {
        ClassCreatedInNewThread temp = new ClassCreatedInNewThread();
        temp.Info("Hello World");
    }
}

----- Original Message ----
From: "Parrish, Ken" <[EMAIL PROTECTED]>
To: [email protected]
Sent: Tuesday, November 13, 2007 4:56:16 PM
Subject: Multi-threaded ASP.NET application not working ...




 
 

<!--

 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;margin-bottom:.0001pt;font-size:12.0pt;font-family:"Times 
New Roman";}
a:link, span.MsoHyperlink
        {color:blue;text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;text-decoration:underline;}
span.EmailStyle17
        {font-family:Arial;color:windowtext;}
 _filtered {margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {}
-->






I am a long time log4net user, but apparently, I have
tripped over a scenario for which I cannot seem to find a solution:
 

  
 

Using:
 

Microsoft Visual Studio Version 2005
 

.NET Framework Version 2.0
 

log4net Version 1.2.10
 

  
 

I have a class library in an assembly which contains a data
cache object that is multithreaded.  It contains a simple worker thread that
polls for changes to the contents of the cache and updates accordingly.  It’s
about as simple a multithreaded pattern as possible.  The class is liberally
instrumented with log4net logging statements.
 

  
 

If executed from a console application, logging works just
fine throughout the cache object / library.
 

  
 

If executed from an ASP.NET Web Application, logging
statements executed on the primary thread work correctly.  HOWEVER, logging
statements executed on the WORKER thread hang.  No output from logging
statements on the worker threads are generated.  The thread proc hangs when 
attempting
to call Log.Info.  If I comment out all logging statements that would be
executed by the worker thread, the application executes flawlessly.
 

  
 

I do mostly server and framework design, so the minutiae of
ASP.NET threading is not my strong suit.
 

  
 

Has anyone encountered similar behavior in an ASP.NET
application?
 

  
 

Has anyone successfully used log4net inside a worker thread
in an ASP.NET application?  If so, I’d be interested in why it works for
you.
 

  
 

Any other clues or suggestions would be most appreciated.
 

  
 

Thank you,
 

  
 

Ken Parrish
 

Gomez, Inc.
 

Lexington, MA
 

  
 

  
 







Reply via email to