Trying to use log4net integration - what am I missing?

1,839 views
Skip to first unread message

George Mauer

unread,
May 20, 2009, 3:20:49 PM5/20/09
to Castle Project Users
I have never used log4net before nor the windsor logging facility, I
have gotten the logging facility to work with the console logger and
now am trying to set it up with log4net and hitting a roadblock.
Going off the information in this article:
http://mikehadlow.blogspot.com/2008/06/more-windsor-love-using-log4net.html
and this earlier post: http://groups.google.com/group/castle-project-users/browse_thread/thread/057036827f7d2038

I have set up this attribute in my AssemblyInfo.cs file
[assembly: log4net.Config.XmlConfigurator(Watch = true)]

and this is my current App.config : http://pastebin.com/f77d62a4c

Yet nothing appears and I break and inspect my Logger property I see
that it is populated with
{log4net.Repository.Hierarchy.DefaultLoggerFactory+LoggerImpl}
Castle.Core.Logging.ILogger
{Castle.Services.Logging.Log4netIntegration.Log4netLogger}
IsDebugEnabled false bool
IsErrorEnabled false bool
IsFatalEnabled false bool
IsFatalErrorEnabled false bool
IsInfoEnabled false bool
IsWarnEnabled false bool


Seems like IsDebugEnabled is not being set. But why?

George Mauer

unread,
May 20, 2009, 3:27:09 PM5/20/09
to Castle Project Users
My facility configuration is in code by the way:
WindsorContainer.AddFacility("facility.logging", new LoggingFacility
(LoggerImplementation.Log4net))

On May 20, 2:20 pm, George Mauer <gma...@gmail.com> wrote:
> I have never used log4net before nor the windsor logging facility, I
> have gotten the logging facility to work with the console logger and
> now am trying to set it up with log4net and hitting a roadblock.
> Going off the information in this article:http://mikehadlow.blogspot.com/2008/06/more-windsor-love-using-log4ne...
> and this earlier post:http://groups.google.com/group/castle-project-users/browse_thread/thr...

Colin Ramsay

unread,
May 20, 2009, 3:49:30 PM5/20/09
to castle-pro...@googlegroups.com
I always have the config in logging.config in my application root, rather than in the app/web.config, I think that's a logging facility thing. You can actually enable log4net internal debugging to find out what's going on in there. Take a look at "How do I enable log4net internal debugging?" in http://logging.apache.org/log4net/release/faq.html

Colin Ramsay

unread,
May 20, 2009, 3:52:29 PM5/20/09
to castle-pro...@googlegroups.com
And actually, looking at your links, the coderant one says "3. Add the log4net config file to the root of the web application:" and the one from the castle list specifies a config file in the facility configuration ("<facility id="loggingfacility" configFile="RSS.KM.DataAccess.Tests.dll.config"")... I think if you omit the configFile attribute then it just uses logging.config.

Jason Meckley

unread,
May 20, 2009, 3:55:00 PM5/20/09
to Castle Project Users
I haven't had a problem with the logging facilty. I keep my log4net
configs in a separate file and I do NOT set the
[assembly: log4net.Config.XmlConfigurator(Watch = true)]

Make sure the logging facility is the first facility registered and
your objects have a public setter for ILogger.

George Mauer

unread,
May 20, 2009, 4:02:24 PM5/20/09
to Castle Project Users
Ok, so now I have the logging.config file
<?xml version="1.0" encoding="utf-8" ?>
<appender name="RollingFile"
type="log4net.Appender.RollingFileAppender">
<file value="di.log" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />

<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level %thread %logger - %message
%newline" />
</layout>
</appender>

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

The logging.config is set to copy always. No attribute in
AssemblyInfo, and nothing in my App.config.
Still no luck.

On May 20, 2:52 pm, Colin Ramsay <colinram...@gmail.com> wrote:
> And actually, looking at your links, the coderant one says "3. Add the
> log4net config file to the root of the web application:" and the one from
> the castle list specifies a config file in the facility configuration
> ("<facility id="loggingfacility"
> configFile="RSS.KM.DataAccess.Tests.dll.config"")... I think if you omit the
> configFile attribute then it just uses logging.config.
>
> On Wed, May 20, 2009 at 8:49 PM, Colin Ramsay <colinram...@gmail.com> wrote:
> > I always have the config in logging.config in my application root, rather
> > than in the app/web.config, I think that's a logging facility thing. You can
> > actually enable log4net internal debugging to find out what's going on in
> > there. Take a look at "How do I enable log4net internal debugging?" in
> >http://logging.apache.org/log4net/release/faq.html
>
> > On Wed, May 20, 2009 at 8:20 PM, George Mauer <gma...@gmail.com> wrote:
>
> >> I have never used log4net before nor the windsor logging facility, I
> >> have gotten the logging facility to work with the console logger and
> >> now am trying to set it up with log4net and hitting a roadblock.
> >> Going off the information in this article:
>
> >>http://mikehadlow.blogspot.com/2008/06/more-windsor-love-using-log4ne...
> >> and this earlier post:
> >>http://groups.google.com/group/castle-project-users/browse_thread/thr...

Colin Ramsay

unread,
May 20, 2009, 4:30:50 PM5/20/09
to castle-pro...@googlegroups.com
That config is wrong, you need the configuration and log4net root elements. Here's a sample from one of my projects:


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <log4net>
        <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
            <to value="colin...@gmail.com" />
            <from value="oh...@test.com" />
            <subject value="Error" />
            <smtpHost value="localhost" />
            <bufferSize value="512" />
            <lossy value="true" />
            <evaluator type="log4net.Core.LevelEvaluator">
                <threshold value="ERROR"/>
            </evaluator>
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />
            </layout>
        </appender>

        <root>
            <priority value="ALL" />
            <appender-ref ref="SmtpAppender" />
        </root>

        <logger name="NHibernate">
            <level value="ERROR" />
        </logger>

        <logger name="Castle">
            <level value="ERROR" />
        </logger>

    </log4net>
</configuration>

George Mauer

unread,
May 20, 2009, 4:52:14 PM5/20/09
to Castle Project Users
Thanks all, I finally got log4net working!
Between colin pointing out that I was missing the config and log4net
nodes and watching the internal debug messages I was able to get it.
For one thing it seems that the default log config name is
log4net.config not logging.config - once I made those 2 changes it
started working.

I do have one more question though. Do I need to have a reference to
log4net.dll or is the Castle.Facilities.Logging.Log4netIntegration
sufficient?

On May 20, 3:30 pm, Colin Ramsay <colinram...@gmail.com> wrote:
> That config is wrong, you need the configuration and log4net root elements.
> Here's a sample from one of my projects:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
>     <log4net>
>         <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
>             <to value="colinram...@gmail.com" />
>             <from value="o...@test.com" />

Colin Ramsay

unread,
May 20, 2009, 5:26:32 PM5/20/09
to castle-pro...@googlegroups.com
Oops, yes, looking at my actual facility config you can see why logging.config was my filename:

<facility
                id="logging"
                type="Castle.Facilities.Logging.LoggingFacility, Castle.Facilities.Logging"
                configFile="logging.config"
                loggingApi="log4net" />

As for the reference question, I don't *think* you need a reference to log4net but you will need it in your application directory.
Reply all
Reply to author
Forward
0 new messages