Logging Block with Threading

Topics: Logging Application Block
Nov 1, 2007 at 8:54 PM
Does the Logging Block work with Threading? I was reworking some code for a Windows Service to execute inside threads, but I'm not seeing anything inside the thread being logged. I'm not sure if this is an EL Logging issue or a Threading issue in the EL 2.0 block. My thread is being created on a method of an object instance in a different assembly. This assembly has its own reference to the Logging block but since it's on a thread I'm assuming that it can't read the app.config file but not sure if the fact that the logging block has already been loaded if that is even required. Any input would be appriciated.

namespace Foo.ServiceController
{
    public class ServiceController
    {
        private Thread mtImportWatcher;
 
        public void Start()
        {
               ImportWatcher miwImportWatcher;
 
                Logger.Write(string.Format("  {0}", "Import enabled"), Category.Verbose, Priority.High);
 
                if (miwImportWatcher == null)
                {
                     Logger.Write(string.Format("  {0}", "Import Threading"), Category.General, Priority.High);
 
                     miwImportWatcher = new ImportWatcher();
                     miwImportWatcher.LocalDirectory = Properties.Settings.Default.localdir;
                    //Create a new Thread from the Run Method on an ImportWatcher object instance
                    mtImportWatcher = new Thread(new ThreadStart(miwImportWatcher.Run));
                    mtImportWatcher.Start();
 
                    Logger.Write(string.Format("{0}", "Started ImportWatcher Thread"), Category.General, Priority.High);
                  }
          }
    }
}
 
namespace Bar.ImportWatcher
{
    private bool mbRun = true;
 
    public class ImportWatcher
    {
           public void Run()
          {
               Logger.Write(string.Format("Import Running: {0}", mbRun.ToString()), Category.General, Priority.Normal);
 
              //Continuous loop of processing
              while (mbRun == true)
              {
                   Logger.Write(string.Format("Processing {0}", "Import"), Category.General, Priority.Normal);
                   //Check the upload directory for files
 
                   ImportFiles();
 
                   Thread.Sleep(1200);
               }
        }
    }
}
Nov 2, 2007 at 6:05 AM

Threads still run in the same domain and has access to app domain and hence config file , i use it entlib with threading all the time

Also web apps run every request on a different worker thread.

Cant see anything in your code maybe config file ?


Regards,

Ben
Nov 2, 2007 at 2:54 PM
Ben you are correct. I discovered what my actual issue was the hard way. I used a UI test harness to test the business logic then I build the Window Service and deploy it. Well the Windows Service runs under different creds that my account so an error was being thrown trying to access a network share on the domain, now this error should have been logged as I log all exceptions, but the Category Sources for Errors had an Email Listener which was crashing before it got to the flat file listener so I never saw the exception in the flat file.

On a side note, have you ever had locking issues with Flat File Listeners when multiple threads are writing to the same log file? If so, did you have to do anything special to lock the resources before writting?
Nov 3, 2007 at 3:23 AM
The only time i have used it is with XMl files for Wcf this got to about 2 Gig but has not been under a lot of multi threaded testing so cant say. I nearly always log to a DB and eventlog for errors.

Regards,

Ben