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 Shaun Lipscombe <sh...@gmsl.co.uk> on 2006/06/29 16:27:06 UTC

Config not honoring appender

Here is my config.  For some reason foo.bar writes to appender A1.  What
have I done wrong?

<log4net>
	<!-- A1 is set to be a ConsoleAppender -->
	<appender name="FileAppender" 								type="log4net.Appender.FileAppender">
		<file value="c:\log-file.txt" />
		<appendToFile value="true" />
		<lockingModel
type="log4net.Appender.FileAppender+MinimalLock" />
		<layout type="log4net.Layout.PatternLayout">
			<conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
		</layout>
	</appender>

	<appender name="EventLogAppender"
type="log4net.Appender.EventLogAppender" >
		<applicationName value="foo.bar.application" />
		<layout type="log4net.Layout.PatternLayout">
			<conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
		</layout>
	</appender>
	

	<root>
		<level value="DEBUG" />
		<appender-ref ref="FileAppender" />
	</root>



	<logger name="foo.bar">
		<level value="WARN" />
		<appender-ref ref="EventLogAppender" />
	</logger>


	<logger name="foo">
		<level value="INFO" />
	</logger>


</log4net>

Re: Config not honoring appender

Posted by Shaun Lipscombe <sh...@gmsl.co.uk>.
* Dean Fiala wrote:

> Your root logger logs to the file appender, and since all log events go to
> to the root logger, it will write to both places.  It is possible to only
> have the logger write to the specified log and not the root logger, but that
> is not something I have wrapped my head around yet.

I had actually considered that this may be the case although I've not
read anything about it in the documentation.

I was thinking that maybe instead of the Appender overriding the other
appender it is infact appended (no pun intended ;-) thus giving two
appenders for the logger foo.bar.  Other options are overridden like
<level> etc.  I guess <appender-ref>'s are accumulated (via inheritance
or otherwise).

Or am I barking up the wrong XML-tree (couldn't resist that one I'm afraid).

RE: Config not honoring appender

Posted by Dean Fiala <df...@celadonlabs.com>.
You need to use the ConfigureAndWatch Method to update the configuration
with a file change.  For example...

        Dim ConfigFile As String = Server.MapPath("~") &
"\config\log4Net.config"
        XmlConfigurator.ConfigureAndWatch(New
System.IO.FileInfo(ConfigFile))

Your root logger logs to the file appender, and since all log events go to
to the root logger, it will write to both places.  It is possible to only
have the logger write to the specified log and not the root logger, but that
is not something I have wrapped my head around yet.

-----Original Message-----
From: Shaun Lipscombe [mailto:shaun.lipscombe@gmsl.co.uk] 
Sent: Thursday, June 29, 2006 11:27 AM
To: Log4NET User
Subject: Re: Config not honoring appender

* Shaun wrote:
> Here is my config.  For some reason foo.bar writes to appender A1.  
> What have I done wrong?


OK it seems to work if I restart my program (I thought the XML config file
was polled, or do you need to specify this fact when you Configure() ?)

However a slightly more curious issue is the fact that it now writes to both
appenders FileAppender and EventLogAppender for WARN level logs.
Or is this normal behaviour?




Re: Config not honoring appender

Posted by Shaun Lipscombe <sh...@gmsl.co.uk>.
* Shaun wrote:
> Here is my config.  For some reason foo.bar writes to appender A1.  What
> have I done wrong?


OK it seems to work if I restart my program (I thought the XML config
file was polled, or do you need to specify this fact when you Configure() ?)

However a slightly more curious issue is the fact that it now writes to
both appenders FileAppender and EventLogAppender for WARN level logs.
Or is this normal behaviour?