Hello Bruno,
configuring log4net directly from the code is my dream too, but
documentation did not give any example how to do this.
It is simple if you need to use the only appender - use
BasicConfigurator:
 
   log4net.Appender.FileAppender fa = new
log4net.Appender.FileAppender();
   fa.AppendToFile = false;
   fa.File = "ipagent.log";
   fa.Layout = new log4net.Layout.PatternLayout("%date{dd-MM-yyyy
HH:mm:ss,fff} %5level [%2thread] %message (%logger{1}:%line)%n");
   fa.Threshold = log4net.Core.Level.Debug;
   fa.ActivateOptions();
   log4net.Config.BasicConfigurator.Configure(fa);
 
I have this tested and it works well. But when configuration is more
complex, I didn't found a way how to make logging to work. Look at this
message
http://www.mail-archive.com/log4net-user@logging.apache.org/msg03890.htm
l, there you find a piece of my (nonworking) code.
If you'll be able to find what is missing there, let me know
 
Radovan Raszka


________________________________

        From: Knittel Bruno [mailto:[EMAIL PROTECTED] 
        Sent: Monday, May 05, 2008 9:32 AM
        To: log4net-user@logging.apache.org
        Subject: log4net configuration withtou Xml file
        
        
        Hello Everyone,
         
            I need to be able to configure log4net without the
XmlConfigurator, that is directly from my code.
            I am aware of the BasicConfigurator but one appender is not
enough for me.
         
            I would like to be able to create some new appenders, remove
(or disable) them and change their
            log threshold at runtime. I am working under Compact
Framework 2.0.
         
            I already took a look at this (
http://www.mail-archive.com/log4net-user@logging.apache.org/msg02895.htm
l ) mail that gave me many informations,
            but did not yet found how to create an appender and register
it not for one logger but for all (and all the ones that will be created
after I registered my appender).
         
            In fact how can I achieve a configuration like the following
file but programmatically:
         
            <configuration>
         <log4net>  
          <appender name="TextLogFileAppender"
type="log4net.Appender.FileAppender" >
           <file value="log.xml" />
           <appendToFile value="true" />
           <layout type="log4net.Layout.XmlLayoutSchemaLog4j" />
           <param name="Threshold" value="ERROR" />
          </appender>
          
          <appender name="ConsoleErrorAppender"
type="log4net.Appender.ConsoleAppender">
           <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger
[%ndc] &lt;%property{auth}&gt; - %message%newline" />
           </layout>
           <param name="Threshold" value="FATAL" />
          </appender>
          
          <appender name="UdpAppender"
type="log4net.Appender.UdpAppender">
           <localPort value="8080" />
           <remoteAddress value="192.168.1.1" />
           <remotePort value="8080" />
           <layout type="log4net.Layout.XmlLayoutSchemaLog4j">
            <locationInfo value="true" />
           </layout>
           <param name="Threshold" value="DEBUG" />
          </appender>
         
          <!-- Setup the root category, add the appenders and set the
default level -->  
          <root>
           <appender-ref ref="TextLogFileAppender" />
           <appender-ref ref="ConsoleErrorAppender" />
           <appender-ref ref="UdpAppender" />
          </root> 
         </log4net>
        </configuration>
         
         
            Best regards and many thanks in advance for any help,
         
            Bruno
         

Reply via email to