Mr. Grabowski,
Thanks for your reply. Your test case is very similar to my scenario. It appears that the problem that I am having is related to using a similar pattern, but in a generic base class. All things being equal, that is the only difference that causes my case to fail. I tried checking for ThreadId output and with MemoryAppender and NullAppender as you suggested, but there was no difference. If my thread class is non-generic, as is your test case, OR if I declare/reference the static logger outside the generic class definition OR if I test in a console test harness-works fine. Only in the case where this is implemented in a generic base class AND it's a static logger declared in the generic base class AND it's executed in an ASP.NET application does it fail. Very bizarre. I suspect some bug or anomaly related to generic class instantiation/initialization by the runtime system in an ASP.NET execution environment. I solved the problem by making the logger a member variable of the class. Inconsistent with our usage pattern in the rest of the code, but will suffice for now. I'd like to know why my case fails, but it's clearly an edge case and there are very few references to this on the Internet. Thank you, Ken Parrish Gomez, Inc. ________________________________ From: Ron Grabowski [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 13, 2007 6:33 PM To: Log4NET User Subject: Re: Multi-threaded ASP.NET application not working ... 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 ... 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
