Menu

#1 log4net logging

open
nobody
None
5
2006-07-05
2006-07-05
Anonymous
No

Instead of the EntLib logging that is now implemented
it schould be better to include the log4net as default
logger class. Because the Hapi projects uses the
"Jakarta Commons Logging (JCL)" logging framework with
the underlaying log4J toolkit.

I supplied a log4netLogger class:

You also need to modify the LogFactory class:

class LogFactory
{
public static Log getLog(System.Type classType)
{
//return new EntLibLogger();
return new
log4netLogger(log4net.LogManager.GetLogger(classType));
}

public static Log getLog(System.String name)
{
//return new EntLibLogger();
return new
log4netLogger(log4net.LogManager.GetLogger(name));
}
}

Dont forget to reference the log4net.dll assembly to
the project!

Discussion

  • Nobody/Anonymous

    log4netLogger class

     
  • Nobody/Anonymous

    Logged In: NO

    To enable log4net in a project or a Nunit test add
    log4net.Config.XmlConfigurator.Configure()
    to your code!

    And modify your app.config file to something like this:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <configSections>
    <section name="log4net"
    type="log4net.Config.Log4NetConfigurationSectionHandler,
    log4net" />
    </configSections>
    <log4net>
    <appender name="ConsoleAppender"
    type="log4net.Appender.ConsoleAppender" >
    <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level
    %logger [%ndc] - %message%newline" />
    </layout>
    </appender>
    <root>
    <level value="INFO" />
    <appender-ref ref="ConsoleAppender" />
    </root>
    </log4net>
    </configuration>

    for more information see http://logging.apache.org/log4net/

     
  • ChadC

    ChadC - 2006-07-11

    Logged In: YES
    user_id=1522633

    I'm not sure how other people feel about this, but Bob and I
    talked about not coupling the logging to either log4net or
    the enterprise logging library. We decided that we should
    use the System.Diagnostics instead of any specific logging
    library. Currently, the 1.1 nHapi uses the
    System.Diagnostics to write all logging to.

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.