log4net question

P

pedrito

I know this isn't the log4net support mailing list, but I was hoping someone
could give me a quick hand with this. I just don't like the idea of
subscribing to a mailing list to ask a single question, have to filter
through all the stuff I don't care about and then unsubscribe after I get
help.

What I'm doing, seems pretty simple, but I can't seem to figure out how to
get it to work. I have the XML data for the configuration as an embedded
resource in my assembly.

It is as follows (just for testing purposes)

<?xml version="1.0" encoding="utf-8" ?>
<appender name="RollingFileAppender"
type="log4net.Appender.RollingFileAppender">
<file value="c:\mylog.log" />
<levelMin value="INFO" />
<levelMax value="FATAL" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
</layout>
</appender>

To load the configuration, I simply get the stream for the logger and do:

XmlConfigurator.Configure(stream);

I verified that the stream does in fact contain my XML by using a stream
reader and reading the contents into a string and the string looks correct.

I get the ILog as follows:

private static readonly log4net.ILog log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

The problem is, after calling XmlConfigurator.Configure(), my log still has
IsInfoEnabled = false, IsDebugEnabled = false, IsErrorEnabled = false, and
IsFatalEnabled = false.

I tried getting the logger after calling XmlConfigurator.Configure(), but
there was no difference.

Their examples are pretty slim and the documentation a bit hard to follow.
There don't appear to be any examples using XmlConfiguration.Configure(), so
that's probably where my problem is.

Anyone have any ideas?

Thanks.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

pedrito said:
It is as follows (just for testing purposes)

<?xml version="1.0" encoding="utf-8" ?>
<appender name="RollingFileAppender"
type="log4net.Appender.RollingFileAppender">
<file value="c:\mylog.log" />
<levelMin value="INFO" />
<levelMax value="FATAL" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
</layout>
</appender>

To load the configuration, I simply get the stream for the logger and do:

XmlConfigurator.Configure(stream);
The problem is, after calling XmlConfigurator.Configure(), my log still has
IsInfoEnabled = false, IsDebugEnabled = false, IsErrorEnabled = false, and
IsFatalEnabled = false.

I tried getting the logger after calling XmlConfigurator.Configure(), but
there was no difference.

I think you need to set at least root level and possible a logger
level.


Something like:

<appender name="console"
type="log4net.Appender.ConsoleAppender,log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<conversionPattern value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<root>
<level value="WARN"/>
<appender-ref ref="console"/>
</root>
<logger name="yourtoplogger">
<level value="ALL"/>
</logger>

Arne

PS: I usually use Configure without arguments and put the stuff
in the regular config.
 
P

pedrito

Arne Vajhøj said:
pedrito said:
It is as follows (just for testing purposes)

<?xml version="1.0" encoding="utf-8" ?>
<appender name="RollingFileAppender"
type="log4net.Appender.RollingFileAppender">
<file value="c:\mylog.log" />
<levelMin value="INFO" />
<levelMax value="FATAL" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
</layout>
</appender>

To load the configuration, I simply get the stream for the logger and do:

XmlConfigurator.Configure(stream);
The problem is, after calling XmlConfigurator.Configure(), my log still
has IsInfoEnabled = false, IsDebugEnabled = false, IsErrorEnabled =
false, and IsFatalEnabled = false.

I tried getting the logger after calling XmlConfigurator.Configure(), but
there was no difference.

I think you need to set at least root level and possible a logger
level.


Something like:

<appender name="console"
type="log4net.Appender.ConsoleAppender,log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<conversionPattern value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<root>
<level value="WARN"/>
<appender-ref ref="console"/>
</root>
<logger name="yourtoplogger">
<level value="ALL"/>
</logger>

Arne

PS: I usually use Configure without arguments and put the stuff
in the regular config.

Thanks so much. I was missing that, plus I was missing the root <log4net>
section. That got me all taken care of. Thanks so much for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top