You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by "Sanders, Brian" <BS...@connextions.com> on 2006/12/15 22:41:04 UTC

Log4net not working as expected

Hello,

I have an issue with log4net that I was sure was not an issue before. I have
a project which is made up of a few other projects. There's an exe and 4
other dlls. Logging from the exe works while logging from the dlls does not.
Like I say, I know this has worked before. I've read thru the documentation
and everything looks identical. Does anyone see what I might be doing wrong
here or know what the cause may be? Thanks.

 

Log4net: 1.2.10.0

Cnxengine.exe: Runs as either a service, or a stand-alone exe, depending on
configuration.

Platform: MS.Net

Cnxengine.exe.Config:

...

<log4net>                      

            <appender name="RollingFile"
type="log4net.Appender.RollingFileAppender">

                        <file value="c:\\CNXHeavy\\Logs\\CNXEngine.log" />

                        <appendToFile value="true" />

                        <rollingStyle value="Date" />

                        <datePattern value="yyyyMMdd" />         

                        <staticLogFileName value="true" />

                        <maxSizeRollBackups value="14" />

                        <!--<maximumFileSize value="1GB" />-->

                        <layout type="log4net.Layout.PatternLayout">

                                    <conversionPattern value="%date %level
%logger[%method:%line] - %message%newline" />

                        </layout>

            </appender>

            <root>

                        <level value="DEBUG" />

                        <appender-ref ref="RollingFile" />

            </root>              

</log4net>

...

 

CNXENgine.cs:

public class CNXEngine : System.ServiceProcess.ServiceBase {

protected log4net.ILog log = log4net.LogManager.GetLogger("CNXEngine");

...

 

public CNXEngine() {

      // This call is required by the Windows.Forms Component Designer.


      InitializeComponent();              


      //Initialize the threadlist

      ThreadList = new ArrayList();

 

      //Get the tasks to run

      log.Debug("GetTasksToRun"); <- Works

      TasksToRun = EngineTasksFactory.GetTasksToRun();

      log.Debug("Finished GetTasksToRun"); <- Works

}

 

public static void Main() 

{

log4net.Config.XmlConfigurator.Configure();

...

if (Convert.ToBoolean(ConfigurationSettings.AppSettings["RunAsService"]))

{

      ...

}

Else

{

      ...

}

}

 

EngineTasksFactory.cs:

public class EngineTasksFactory

{

      protected static log4net.ILog log =
log4net.LogManager.GetLogger("EngineTasksFactory");

            ...

 

public static EngineTaskList GetTasksToRun()

{

      log.Info("Creating EngineTaskList"); <- Does not work

      EngineTaskList tasks = new EngineTaskList();

                                          

      tasks.Add(new OrderRoutingTask());

      log.Debug("Created EngineTaskList");

      return tasks;

}

 

Brian Sanders


Re: Log4net not working as expected

Posted by Karel Kral <kr...@volny.cz>.
Do tou have declared AliasRepository for these dlls?

from my assemblyinfo.vb:

<Assembly: XmlConfigurator(ConfigFileExtension:="log4net.config",
Watch:=True)>
<Assembly: AliasRepository("Anete.Devices")>
<Assembly: AliasRepository("Anete.Kasa8.Common")>
<Assembly: AliasRepository("Anete.Kasa8.Manager")>
<Assembly: AliasRepository("Anete.Kasa8.Prodej")>

Anete.Devices etc. are namespaces of dlls. I also must to recommend you
that create loggers locally in class where you wond to to logging.

Sanders, Brian wrote:
> Hello,
> 
> I have an issue with log4net that I was sure was not an issue before. I
> have a project which is made up of a few other projects. There’s an exe
> and 4 other dlls. Logging from the exe works while logging from the dlls
> does not. Like I say, I know this has worked before. I’ve read thru the
> documentation and everything looks identical. Does anyone see what I
> might be doing wrong here or know what the cause may be? Thanks.
> 
>  
> 
> Log4net: 1.2.10.0
> 
> Cnxengine.exe: Runs as either a service, or a stand-alone exe, depending
> on configuration.
> 
> Platform: MS.Net
> 
> Cnxengine.exe.Config:
> 
> …
> 
> <log4net>                     
> 
>             <appender name="RollingFile"
> type="log4net.Appender.RollingFileAppender">
> 
>                         <file value="c:\\CNXHeavy\\Logs\\CNXEngine.log" />
> 
>                         <appendToFile value="true" />
> 
>                         <rollingStyle value="Date" />
> 
>                         <datePattern value="yyyyMMdd" />        
> 
>                         <staticLogFileName value="true" />
> 
>                         <maxSizeRollBackups value="14" />
> 
>                         <!--<maximumFileSize value="1GB" />-->
> 
>                         <layout type="log4net.Layout.PatternLayout">
> 
>                                     <conversionPattern value="%date
> %level  %logger[%method:%line] - %message%newline" />
> 
>                         </layout>
> 
>             </appender>
> 
>             <root>
> 
>                         <level value="DEBUG" />
> 
>                         <appender-ref ref="RollingFile" />
> 
>             </root>             
> 
> </log4net>
> 
> …
> 
>  
> 
> CNXENgine.cs:
> 
> public class CNXEngine : System.ServiceProcess.ServiceBase {
> 
> protected log4net.ILog log = log4net.LogManager.GetLogger("CNXEngine");
> 
> …
> 
>  
> 
> public CNXEngine() {
> 
>       // This call is required by the Windows.Forms Component
> Designer.            
> 
>       InitializeComponent();             
> 
> 
>       //Initialize the threadlist
> 
>       ThreadList = new ArrayList();
> 
>  
> 
>       //Get the tasks to run
> 
>       log.Debug("GetTasksToRun"); <- Works
> 
>       TasksToRun = EngineTasksFactory.GetTasksToRun();
> 
>       log.Debug("Finished GetTasksToRun"); <- Works
> 
> }
> 
>  
> 
> public static void Main()
> 
> {
> 
> log4net.Config.XmlConfigurator.Configure();
> 
> …
> 
> if (Convert.ToBoolean(ConfigurationSettings.AppSettings["RunAsService"]))
> 
> {
> 
>       …
> 
> }
> 
> Else
> 
> {
> 
>       …
> 
> }
> 
> }
> 
>  
> 
> EngineTasksFactory.cs:
> 
> public class EngineTasksFactory
> 
> {
> 
>       protected static log4net.ILog log =
> log4net.LogManager.GetLogger("EngineTasksFactory");
> 
>             …
> 
>  
> 
> public static EngineTaskList GetTasksToRun()
> 
> {
> 
>       log.Info("Creating EngineTaskList"); <- Does not work
> 
>       EngineTaskList tasks = new EngineTaskList();
> 
>                                          
> 
>       tasks.Add(new OrderRoutingTask());
> 
>       log.Debug("Created EngineTaskList");
> 
>       return tasks;
> 
> }
> 
>  
> 
> Brian Sanders
>