Hi Ron,
The loghelper is log helper :). I can send it to you directly if you allow. 
The idea is to have a separate logger for each of modules. 
So I create 
m_Module1logger=new cLoghelper()
m_Module1logger.Initlogger("Logger_for_module1") //This switches m_log to
true or false, depends on if Logger1 is switched on in registry
..
If Module1logger.m_log() then  Module1logger.log.Debug("gjgjhguzgu")
This worked very reliable all the time until now. Can you see what goes
wrong with log4net (I mean what exactly is misconfigured)? 
Thanks a lot,
Boni



--------------------Just cut-outs---
using  log4net;
using log4net.Appender;
using System.Diagnostics; 
using System.IO; 
using System.Text.RegularExpressions; 
using  System.Windows.Forms;
using System.Reflection;
using Microsoft.Win32;

        public class cLogHelper {       
                ...
        private static FileAppender m_FileAppender;
        private static FileAppender.LockingModelBase m_LockingModel;
        private bool m_log; 
        private ILog m_logger;
        private static bool Reconfig;
                

                public void Error( object aMsg,System.Exception aEx){
                        PrintErrToScreen();
                        m_logger.Error(aMsg,aEx);
                        m_logger.Info(EnvInfo());

                }

                public void InitLogger(string aLoggerID) {
                        this.m_logger = LogManager.GetLogger(aLoggerID);
                        RegistryKey key1 =
Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("XXX").OpenSubKey("Y
YY").OpenSubKey(cLogHelper.m_Version);
                        string loglevel =
key1.GetValue("LoggerName").ToString(); 
                        Regex regex1 = new Regex("((^)|(.* +))" + aLoggerID
+ "(( +.*)|($))", RegexOptions.IgnoreCase);
                        Debug.Assert(loglevel != null);
                        if (loglevel != null) {
                        this.m_log = regex1.IsMatch(loglevel);
                                
                
                        }
                }




                private static void ConfigureLogger() {
                        log4net.Util.LogLog.InternalDebugging=true;
                        if (cLogHelper.Reconfig) {
                                return; 
                        }

                        ...
                        cLogHelper.m_FileAppender = new FileAppender();
                        cLogHelper.m_FileAppender.Layout = new
log4net.Layout.PatternLayout("[%date{dd MMM yyyy HH:mm:ss,fff}] %level
%logger  - %message%newline");
                        cLogHelper.m_FileAppender.File = path_to_log + @"\"
+ cLogHelper.m_logger_file_name;
                        cLogHelper.m_FileAppender.LockingModel =
cLogHelper.m_LockingModel;
                        cLogHelper.m_FileAppender.ImmediateFlush = true;
                        cLogHelper.m_FileAppender.AppendToFile = true;
                        

                        cLogHelper.m_FileAppender.ActivateOptions();
                        try {
        
log4net.Config.BasicConfigurator.Configure(cLogHelper.m_FileAppender);
                        }
                        catch (System.Exception exception) {
                                //log file is not initialized on this point
so we can't log error
                                //on other hand the failing delete of log
file is not really important
                                //so I better skip log message instead of
confusing the users

                                Debug.Assert(false, "Logger couldn't be
configured!!!!");
                                return;
                        }
                        cLogHelper.Reconfig = true;

                }

Reply via email to