PC Review

Thread Tools Rate Thread

Log4net trouble

Posts: n/a
      9th Aug 2005

anyone can help with log4net?
i'm not sure i understand log4net object model properly...
i'm trying to configure log4net programmatically, in order to assign
different custom appenders to some custom loggers (run-time) and (i
think) i've been able to add new custom loggers to the root logger of
the repository. i've also added one appender for each custom logger.

this is the code snippet i wrote:
log4net.Repository.Hierarchy.Hierarchy hier =

//customizing server logger(s)
log4net.Repository.Hierarchy.Logger ServerLogger = null;
ServerLogger = hier.LoggerFactory.CreateLogger("ServerLogger");
ServerLogger.Level = log4net.Core.Level.Info;
ServerLogger.AddAppender(CreateTextBoxAppender()); //add textbox

//customizing client logger(s)
log4net.Repository.Hierarchy.Logger ClientLogger = null;
ClientLogger = hier.LoggerFactory.CreateLogger("ClientLogger");
ClientLogger.Level = log4net.Core.Level.Info;
ClientLogger.AddAppender(CreateTextWriterAppender()); //add textwriter

hier.Configured = true;
LogManager.GetRepository().Configured = true;
XmlConfigurator.ConfigureAndWatch(LogManager.GetRepository(), new
FileInfo(filename)); //filename = App.config file path
now, when i try to retrieve the custom logger i have just created using
LogManager.GetRepository().GetLogger("ServerLogger") or
log4net create a new Logger instance named "ServerLogger" as well,
without any appenders.
how if i need to use my custom logger inside any class of my

thanks in advice

Reply With Quote

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Log4net trouble Joneleth Microsoft Dot NET Framework 0 9th Aug 2005 05:57 PM
Log4net trouble Joneleth Microsoft C# .NET 0 9th Aug 2005 03:21 PM
Using log4net with a Windows service Gerald Aden Microsoft Dot NET Framework 1 28th Jan 2005 08:55 PM
log4Net Patrick Microsoft Dot NET Framework 11 22nd Nov 2004 08:16 AM
Log4Net help wanted Raj Dhrolia Microsoft ASP .NET 0 22nd Dec 2003 01:28 PM




All times are GMT +1. The time now is 01:16 PM.