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 Todd Webb <we...@gmail.com> on 2012/05/24 15:42:16 UTC

Inconsistency of internal logging and behavior in log4net in ASP.NET MVC (multi-assembly)

I have a multi-assembly ASP.NET MVC application.  I reviewed the recent
posts on a similar topic, but decided that my problem merited a new thread.

 

I am configuring log4net is a separate configuration file and initialize
log4net with this statement:

 

[assembly: log4net.Config.XmlConfigurator(ConfigFile =
"WebApplication.log4net", Watch=true)]

 

I am attempting to log from the web application assembly and from another
assembly in the solution.  I enabled log4net internal logging and received
the following:

 

 

log4net: XmlConfigurator: loading XML configuration

log4net: XmlConfigurator: Configuring Repository
[log4net-default-repository]

log4net: XmlHierarchyConfigurator: Configuration update mode [Merge].

log4net: XmlHierarchyConfigurator: Logger [root] Level string is [ERROR].

log4net: XmlHierarchyConfigurator: Logger [root] level set to
[name="ERROR",value=70000].

log4net: XmlHierarchyConfigurator: Loading Appender [DebugAppender] type:
[log4net.Appender.DebugAppender]

log4net: XmlHierarchyConfigurator: Setting Property [ImmediateFlush] to
Boolean value [True]

log4net: XmlHierarchyConfigurator: Setting Property [Layout] to object
[log4net.Layout.SimpleLayout]

log4net: XmlHierarchyConfigurator: Created Appender [DebugAppender]

log4net: XmlHierarchyConfigurator: Adding appender named [DebugAppender] to
logger [root].

log4net: XmlHierarchyConfigurator: Retrieving an instance of
log4net.Repository.Logger for logger
[WebApplication.Controllers.AppController].

log4net: XmlHierarchyConfigurator: Setting
[WebApplication.Controllers.AppController] additivity to [True].

log4net: XmlHierarchyConfigurator: Logger
[WebApplication.Controllers.AppController] Level string is [DEBUG].

log4net: XmlHierarchyConfigurator: Logger
[WebApplication.Controllers.AppController] level set to
[name="DEBUG",value=30000].

log4net: XmlHierarchyConfigurator: Adding appender named [DebugAppender] to
logger [WebApplication.Controllers.AppController].

log4net: XmlHierarchyConfigurator: Retrieving an instance of
log4net.Repository.Logger for logger
[WebApplication.Domain.Implementation.DomainImpl].

log4net: XmlHierarchyConfigurator: Setting
[WebApplication.Domain.Implementation.DomainImpl] additivity to [True].

log4net: XmlHierarchyConfigurator: Logger
[WebApplication.Domain.Implementation.DomainImpl] Level string is [DEBUG].

log4net: XmlHierarchyConfigurator: Logger
[WebApplication.Domain.Implementation.DomainImpl] level set to
[name="DEBUG",value=30000].

log4net: XmlHierarchyConfigurator: Adding appender named [DebugAppender] to
logger [WebApplication.Domain.Implementation.DomainImpl].

log4net: XmlHierarchyConfigurator: Hierarchy Threshold []

 

I am interested in the logger at
WebApplication.Domain.Implementation.DomainImpl and see that it is set to
debug.  However, when I access the logger in the debugger and print its
state I get this:

 

DomainImpl.log       {Common.Logging.Simple.NoOpLogger} Common.Logging.ILog
{Common.Logging.Simple.NoOpLogger}

[Common.Logging.Simple.NoOpLogger] {Common.Logging.Simple.NoOpLogger}
Common.Logging.Simple.NoOpLogger

IsDebugEnabled       false  bool

IsErrorEnabled       false  bool

IsFatalEnabled       false  bool

IsInfoEnabled false  bool

IsTraceEnabled       false  bool

IsWarnEnabled false  bool

              

 

The only thing that made sense to me was that I was accessing a different
logger in my code than the one that was referenced in the log4net log.
However, I only see two loggers created, one each for my web application and
domain assemblies. I don't see any logger created that has no logging levels
enabled.  I am stumped and welcome any guidance. For example, when should I
get a NoOpLogger?

 

 

 


Re: Inconsistency of internal logging and behavior in log4net in ASP.NET MVC (multi-assembly)

Posted by Ron Grabowski <ro...@yahoo.com>.
Is "Common.Logging" your wrapper around log4net or another library?


________________________________
 From: Todd Webb <we...@gmail.com>
To: log4net-user@logging.apache.org 
Sent: Thursday, May 24, 2012 9:42 AM
Subject: Inconsistency of internal logging and behavior in log4net in ASP.NET MVC (multi-assembly)
 

I have a multi-assembly ASP.NET MVC application.  I reviewed the recent posts on a similar topic, but decided that my problem merited a new thread.
 
I am configuring log4net is a separate configuration file and initialize log4net with this statement:
 
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "WebApplication.log4net", Watch=true)]
 
I am attempting to log from the web application assembly and from another assembly in the solution.  I enabled log4net internal logging and received the following:
 
 
log4net: XmlConfigurator: loading XML configuration
log4net: XmlConfigurator: Configuring Repository [log4net-default-repository]
log4net: XmlHierarchyConfigurator: Configuration update mode [Merge].
log4net: XmlHierarchyConfigurator: Logger [root] Level string is [ERROR].
log4net: XmlHierarchyConfigurator: Logger [root] level set to [name="ERROR",value=70000].
log4net: XmlHierarchyConfigurator: Loading Appender [DebugAppender] type: [log4net.Appender.DebugAppender]
log4net: XmlHierarchyConfigurator: Setting Property [ImmediateFlush] to Boolean value [True]
log4net: XmlHierarchyConfigurator: Setting Property [Layout] to object [log4net.Layout.SimpleLayout]
log4net: XmlHierarchyConfigurator: Created Appender [DebugAppender]
log4net: XmlHierarchyConfigurator: Adding appender named [DebugAppender] to logger [root].
log4net: XmlHierarchyConfigurator: Retrieving an instance of log4net.Repository.Logger for logger [WebApplication.Controllers.AppController].
log4net: XmlHierarchyConfigurator: Setting [WebApplication.Controllers.AppController] additivity to [True].
log4net: XmlHierarchyConfigurator: Logger [WebApplication.Controllers.AppController] Level string is [DEBUG].
log4net: XmlHierarchyConfigurator: Logger [WebApplication.Controllers.AppController] level set to [name="DEBUG",value=30000].
log4net: XmlHierarchyConfigurator: Adding appender named [DebugAppender] to logger [WebApplication.Controllers.AppController].
log4net: XmlHierarchyConfigurator: Retrieving an instance of log4net.Repository.Logger for logger [WebApplication.Domain.Implementation.DomainImpl].
log4net: XmlHierarchyConfigurator: Setting [WebApplication.Domain.Implementation.DomainImpl] additivity to [True].
log4net: XmlHierarchyConfigurator: Logger [WebApplication.Domain.Implementation.DomainImpl] Level string is [DEBUG].
log4net: XmlHierarchyConfigurator: Logger [WebApplication.Domain.Implementation.DomainImpl] level set to [name="DEBUG",value=30000].
log4net: XmlHierarchyConfigurator: Adding appender named [DebugAppender] to logger [WebApplication.Domain.Implementation.DomainImpl].
log4net: XmlHierarchyConfigurator: Hierarchy Threshold []
 
I am interested in the logger at WebApplication.Domain.Implementation.DomainImpl and see that it is set to debug.  However, when I access the logger in the debugger and print its state I get this:
 
DomainImpl.log       {Common.Logging.Simple.NoOpLogger} Common.Logging.ILog {Common.Logging.Simple.NoOpLogger}
[Common.Logging.Simple.NoOpLogger] {Common.Logging.Simple.NoOpLogger} Common.Logging.Simple.NoOpLogger
IsDebugEnabled       false  bool
IsErrorEnabled       false  bool
IsFatalEnabled       false  bool
IsInfoEnabled false  bool
IsTraceEnabled       false  bool
IsWarnEnabled false  bool
              
 
The only thing that made sense to me was that I was accessing a different logger in my code than the one that was referenced in the log4net log.  However, I only see two loggers created, one each for my web application and domain assemblies. I don’t see any logger created that has no logging levels enabled.  I am stumped and welcome any guidance. For example, when should I get a NoOpLogger?

Re: Inconsistency of internal logging and behavior in log4net in ASP.NET MVC (multi-assembly)

Posted by Michele Lepri <mi...@gmail.com>.
Hello Todd,
I will try to answer =)

You are doing this two things:
- starting log4net using the XmlConfigurator assembly-attribute
- using Commong.Logging as abstract wrapper logging library

In your (I think trace) log you are seeing only NoOpLogger: this is the
default (no-logging) logger of Commong.Logging.

What you should do is simply configure Common loggin to use log4net and
use its adapter.
Read the netcommon-reference.pdf released with Commong.Logging for more
info.
In your case this should be the right configuration
<configuration>
<common>
<logging>
<factoryAdapter
type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter,
Common.Logging.Log4net">
<arg key="configType" value="FILE-WATCH" />
<arg key="configFile" value="~/WebApplication.log4net" />
</factoryAdapter>
</logging>
</common>
</configuration>

The you can remove the log4net XmlConfigurator attribute, and of course
the reference to log4net assembly in your project.

If you are using the last release of log4net with the new key, you must
recompile the log4net aadapter.

Tell us if you need more help.

regards
michele

Il 24/05/2012 15:42, Todd Webb ha scritto:
> I have a multi-assembly ASP.NET MVC application.  I reviewed the recent
> posts on a similar topic, but decided that my problem merited a new thread.
> 
>  
> 
> I am configuring log4net is a separate configuration file and initialize
> log4net with this statement:
> 
>  
> 
> [assembly: log4net.Config.XmlConfigurator(ConfigFile =
> "WebApplication.log4net", Watch=true)]
> 
>  
> 
> I am attempting to log from the web application assembly and from
> another assembly in the solution.  I enabled log4net internal logging
> and received the following:
> 
>  
> 
>  
> 
> log4net: XmlConfigurator: loading XML configuration
> 
> log4net: XmlConfigurator: Configuring Repository
> [log4net-default-repository]
> 
> log4net: XmlHierarchyConfigurator: Configuration update mode [Merge].
> 
> log4net: XmlHierarchyConfigurator: Logger [root] Level string is [ERROR].
> 
> log4net: XmlHierarchyConfigurator: Logger [root] level set to
> [name="ERROR",value=70000].
> 
> log4net: XmlHierarchyConfigurator: Loading Appender [DebugAppender]
> type: [log4net.Appender.DebugAppender]
> 
> log4net: XmlHierarchyConfigurator: Setting Property [ImmediateFlush] to
> Boolean value [True]
> 
> log4net: XmlHierarchyConfigurator: Setting Property [Layout] to object
> [log4net.Layout.SimpleLayout]
> 
> log4net: XmlHierarchyConfigurator: Created Appender [DebugAppender]
> 
> log4net: XmlHierarchyConfigurator: Adding appender named [DebugAppender]
> to logger [root].
> 
> log4net: XmlHierarchyConfigurator: Retrieving an instance of
> log4net.Repository.Logger for logger
> [WebApplication.Controllers.AppController].
> 
> log4net: XmlHierarchyConfigurator: Setting
> [WebApplication.Controllers.AppController] additivity to [True].
> 
> log4net: XmlHierarchyConfigurator: Logger
> [WebApplication.Controllers.AppController] Level string is [DEBUG].
> 
> log4net: XmlHierarchyConfigurator: Logger
> [WebApplication.Controllers.AppController] level set to
> [name="DEBUG",value=30000].
> 
> log4net: XmlHierarchyConfigurator: Adding appender named [DebugAppender]
> to logger [WebApplication.Controllers.AppController].
> 
> log4net: XmlHierarchyConfigurator: Retrieving an instance of
> log4net.Repository.Logger for logger
> [WebApplication.Domain.Implementation.DomainImpl].
> 
> log4net: XmlHierarchyConfigurator: Setting
> [WebApplication.Domain.Implementation.DomainImpl] additivity to [True].
> 
> log4net: XmlHierarchyConfigurator: Logger
> [WebApplication.Domain.Implementation.DomainImpl] Level string is [DEBUG].
> 
> log4net: XmlHierarchyConfigurator: Logger
> [WebApplication.Domain.Implementation.DomainImpl] level set to
> [name="DEBUG",value=30000].
> 
> log4net: XmlHierarchyConfigurator: Adding appender named [DebugAppender]
> to logger [WebApplication.Domain.Implementation.DomainImpl].
> 
> log4net: XmlHierarchyConfigurator: Hierarchy Threshold []
> 
>  
> 
> I am interested in the logger at
> WebApplication.Domain.Implementation.DomainImpl and see that it is set
> to debug.  However, when I access the logger in the debugger and print
> its state I get this:
> 
>  
> 
> DomainImpl.log       {Common.Logging.Simple.NoOpLogger}
> Common.Logging.ILog {Common.Logging.Simple.NoOpLogger}
> 
> [Common.Logging.Simple.NoOpLogger] {Common.Logging.Simple.NoOpLogger}
> Common.Logging.Simple.NoOpLogger
> 
> IsDebugEnabled       false  bool
> 
> IsErrorEnabled       false  bool
> 
> IsFatalEnabled       false  bool
> 
> IsInfoEnabled false  bool
> 
> IsTraceEnabled       false  bool
> 
> IsWarnEnabled false  bool
> 
>              
> 
>  
> 
> The only thing that made sense to me was that I was accessing a
> different logger in my code than the one that was referenced in the
> log4net log.  However, I only see two loggers created, one each for my
> web application and domain assemblies. I don’t see any logger created
> that has no logging levels enabled.  I am stumped and welcome any
> guidance. For example, when should I get a NoOpLogger?
> 
>  
> 
>  
> 
>  
> 


-- 
http://michelelepri.blogspot.com/